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

using namespace std;

int main() {
    int t, i, d, digit, digit_count;
    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) {
            digit_count = 0;
            ten = 1;
            while (j/ten > 0) {
                ten *= 10;
                digit_count++;
            }
            ten = 1;
            mul = 1;
            for (d = 0; d < digit_count; ++d) {
                digit = j%(ten*10)/ten;
                if (digit == 0) break;
                ten *= 10;
                mul *= digit;
            }
            if (find(v.begin(), v.end(), mul) == v.end()) v.push_back(mul);
        }
        printf("%d\n", v.size());
    }
}