#include <bits/stdc++.h>
#define N n[i]
#define LIMIT 200010

using namespace std;

int main() {
    int t, i, d, digit;
    size_t n[LIMIT];
    size_t ten, mul, j;

    scanf("%d", &t);
    for (i = 0; i < t; ++i) {
        scanf("%d", &N);
    }

    for (i = 0; i < t; ++i) {
        vector<size_t> v = {};
        for (j = 1; j <= N; ++j) {
            string str = to_string(j);
            ten = 1;
            mul = 1;
            for (d = 0; d < str.length(); ++d) {
                digit = j%(ten*10)/ten;
                ten *= 10;
                mul *= digit;
                if (mul == 0) break;
            }
            bool has = false;
            for (d = 0; d < v.size(); ++d) {
                if (v[d] == mul) {
                    has = true;
                    break;
                }
            }
            if (!has) v.push_back(mul);
        }
        printf("%d\n", v.size());
    }
}