#include<bits/stdc++.h>
#define int long long

using namespace std;

int B(int n) {
  set<int> s;
  for (int i = 1; i <= n; i++) {
    int x = i, r = 1;
    while (x > 0) {
      r *= (x % 10);
      x /= 10;
    }
    s.insert(r);
  }
  return s.size();
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, b = 0;
    cin >> n;
    b = B(n);
    cout << b << "\n";
  }
  return 0;
}