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

unordered_set<ll> seen;
unordered_set<ll> trazeni;
unordered_map<ll, ll> ans;

int main() {
    int T;
    cin >> T;
    ll a;
    vector<ll> n;
    ll MAXN = 0;
    for (int i = 0; i < T; i++) {
        cin >> a;
        trazeni.insert(a);
        n.push_back(a);
        if (a > MAXN) MAXN = a;
    }

    ans[1] = 1;
    seen.insert(1);

    ll prev = 1;
    ll now, k;
    for (ll i = 2; i <= MAXN; i++) {
        if (prev != 0) {
            now = prev / ((i-1)%10) * (i%10);
        } else {
            now = 1, k = i;
            while (k != 0) {
                now *= k%10;
                k/=10;
            }
        }
        prev = now;
        seen.insert(now);
        if (trazeni.count(i)) {
            ans[i] = seen.size();
        }
    }

    for (ll &i : n) {
        cout << ans[i] << "\n";
    }
}