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

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

void solve() {
    for (int i = 1; i <= MAXN; i++) {
        int 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();
    int n;
    for (int i = 0; i < T; i++) {
        cin >> n;
        cout << ans[n] << "\n";
    }
}