#include <bits/stdc++.h>

using namespace std;

int sabirajCifre(int n) {
    int m = 0;
    while (n != 0) {
        m += n % 10;
        n -= n % 10;
        n = n / 10;
    }
    return m;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int T;
    cin >> T;

    vector<int> brojevi(T);
    vector<int> resenja(T);
    int max1;

    for (int i = 0; i < T; i++) {
        cin >> brojevi[i];
    }

    for (int i = 0; i < T; i++) {
        for (int j = 0; j < brojevi[i] + 1; j++) {
            if (sabirajCifre(j) > max1) max1 = sabirajCifre(j);
            cout << "Novi max je " << max1 << endl;
        }
        resenja[i] = max1;
        max1 = 0;
    }

    for (int i = 0; i < T; i++) {
        cout << resenja[i];
    }
}