#include <bits/stdc++.h>

#define ll long long

void solve()
{
    ll n, br = 1;
    std::unordered_set<ll> cnt;
    std::unordered_map<ll, ll> map;

    for(ll i = 0; i < 10; i++)
        map[i] = i;
    map[10] = 0;

    std::cin >> n;

    for(ll i = 1; i <= n; i++)
    {
        map[i + 10] = map[br] * map[(i % 10)];
        if(i % 10 == 0)
            br++;
        
        cnt.insert(map[i]);
    }

    std::cout << cnt.size() << "\n";
}

int main()
{
    int t;
    std::cin >> t;
    
    while(t--)
        solve();

    return 0;
}