#include<iostream>
#include<vector>

using namespace std;

int main (){
    int t;
    cin >> t;
    vector <int> n(t);

    vector <int> product;
    int rez = 1;

    for (int i = 0; i < t; i++){
        cin >> n[i];
    }
    for (int i = 0; i < t; i++){
        for (int j = 1; j <= n[i]; j++){
            rez = 1;
            int j2 = j;
            while (j2 != 0){
                rez = rez * (j % 10);
                j2 = j2 / 10;
            }

            bool upada = true;
            for (int h = 0; h < product.size(); h++){
                if (rez == product[h]) upada = false;
            }
            if (upada) product.push_back(rez);

        }
        cout << product.size() << " ";
        product.clear();
    }
}
//mora brze -- popravi