#include <bits/stdc++.h>
#define ll int
#define MAXN 1000000
using namespace std;

ll n;
unordered_set<int> seen;
int ans[MAXN];

void solve() {
    for (ll i = 1; i <= MAXN; i++) {
        ll mul = 1, a = i;
        while (a != 0) {
            mul *= a % 10;
            a /= 10;
        }
        seen.insert(mul);
        ans[i] = seen.size();
    }
}

int main() {
    int T;
    cin >> T;
    solve();
    for (int i = 1; i <= T; i++) {
        cin >> n;
        cout << ans[n] << "\n";
    }
}