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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
    vector<int> vec(t);
    for(int i = 0;i < t;i++){
        int n;
        cin >> n;
        vec[i] = n;
    }
    sort(vec.begin(), vec.end());

    unordered_map<int, int> p;
    unordered_map<int, bool> ch;
    int k = 1;
    p[1] = 1;
    ch[1] = true;

    int c = 10, l = 0;
    if(vec[l] == 1) {
        cout << 1 << '\n';
        l++;
    }
    for(int i = 2;i <= vec[t-1];i++){

        if(i == c * 10) c *= 10;
        else{
            if(i < 10) {k++; ch[i] = true; p[i] = i;}
            else {
                int b1 = i / c, b2 = i % c;
                if(i != 10 && b2 * 10 < c) continue;
                if(!ch[b1 * p[b2]]) {
                    k++;
                    ch[b1 * p[b2]] = true;
                    p[b1 * p[b2]] = b1 * p[b2];
                }
            }
        }
        if(i == vec[l]){
            cout << k << '\n';
            l++;
            if(l == t) break;
        }
    }

    return 0;
}