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

int abakus(int t){
    int counter = 0;
    vector<int> vec;
    for(int i = 1; i < t + 1; i++){
        int temp = 1;
        int h = i / 1000;
        int s = (i - h * 1000) / 100;
        int d = (i - h * 1000 - s * 100) / 10;
        int j = i % 10;
        if(i < 10){
            temp = j;
        }
        else if(i < 100){
            temp = j * d;
        }
        else if(i < 1000){
            temp = j * d * s;
        }
        else{
            temp = j * d * s * h;
        }
        if(std::count(vec.begin(), vec.end(), temp) == 0){
            vec.push_back(temp);
        }
    }
    counter = vec.size();
    return counter;

}

int main(){
    int n;
    cin>>n;
    vector<int> nums(n);
    for(int i = 0; i < n; i++)cin>>nums[i];
    for(int i = 0; i < n; i++){
        int tmp = abakus(nums[i]);
        cout<<tmp<<endl;
    }
    return 0;
}