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

int t, tpm[200005];

bitset<LONG_MAX> a;

int sumac(long long x) {
    int suma = 0;
    while (x >= 1) {
        suma += x % 10;
        x /= 10;
    }
    return suma;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> t;


    for (int tp = 0; tp < t; tp++) {
        long long n;
        int br = 0;

        cin >> n;

        a.reset();

        for (long long i = 0; i < n; i++) {
            int suma = sumac(i);

            if (a[suma] == 0) {
                a[suma] = 1;
                br++;
            }
        }

        tpm[tp] = br;
    }

    for (int tp = 0; tp < t; tp++) cout << tpm[tp] << '\n';

    return 0;
}