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

using namespace std;

int main() {
    int t, i, d, digit, digit_count;
    int n[LIMIT];
    int ten, mul, j, biggest = 0;

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

    map<int, int> mem{};
    for (j = 1; j <= biggest; ++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;
            ten *= 10;
            mul *= digit;
            if (mul == 0) break;
        }
        mem[j] = mul;
    }

    for (i = 0; i < t; ++i) {
        set<int> s{};
        for (d = 1; d <= N; ++d) s.insert(mem[d]);
        printf("%d\n", s.size());
        s.clear();
    }
    mem.clear();
}