#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
    long long n;

    if (!(cin >> n)) return 0;
    long long a[n];

    for(long long i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for(long long i = 0; i < n; i++)
    {
        vector<long long> b;
        long long res = 1;

        for(long long j = 1; j <= a[i]; j++)
        {
            res = 1;
            long long g = j;
            while(g >= 1)
            {
                res = res * (g % 10);
                g = g / 10;
            }
            b.push_back(res);
        }

        set<long long> br(b.begin(), b.end());
        cout << br.size() << endl;
    }

    return 0;
}