#include <bits/stdc++.h>

using namespace std;

int funkcija (int n) {
    int br1 = 1;
    int o = 1;
    int s = 1;
    int c = 0;
    int br2 = 0;
    vector<int> v1;
    for (int i = 1; i <= n; i++) {
        br1 = 1;
        s = i;
        while (s > 0) {
            o = s % 10;
            br1 = br1 * o;
            s = s / 10;
        }
        v1.push_back(br1);
    }
    for (int i = 0; i < n; i++) {
        c = count(v1.begin(), v1.end(), i);
        if (c > 0) {
            br2++;
        }
    }
    return br2;
}

int main()
{
    int n, x; vector<int> v1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x;
        v1.push_back(x);
    }
    for (int i = 0; i < v1.size(); i++) {
        cout << funkcija(v1[i]) << '\n';
    }
}