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

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

    unordered_map<int, int> p;
    int maxn = 100000;
    int arr[maxn + 1];
    arr[1] = 1;
    p[1] = 1;

    int c = 10;
    for(int i = 2;i <= maxn;i++){
        arr[i] = arr[i-1];
        if(i == c * 10) {c *= 10; continue;}

        if(i < 10) {arr[i]++; p[i] = i;}
        else {
            int b1 = i / c, b2 = i % c;
            if(i != 10 && b2 * 10 < c) continue;
            if(p[b1 * p[b2]] == 0) {
                arr[i]++;
                p[b1 * p[b2]] = 1;
            }
        }
    }

    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        cout << arr[n] << '\n';
    }

    return 0;
}