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

using namespace std;

int main (){
    int t;
    cin >> t;

    vector <int> n(t);

    set <int> product;
    int rez = 1;
    
    for (int i = 0; i < t; i++){
        cin >> n[i];
        for (int j = 1; j <= n[i]; j++){
            rez = 1;
            while (j != 0){
                rez *= j % 10;
                j /= 10;
                if (rez == 0) break;
            }
            product.insert(rez);
        }
        cout << product.size();
    }
}