#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int T;
    cin >> T;
    int a;
    vector<int> upiti(T);
    for (int i = 0; i < T; i++)
    {
        cin >> upiti[i];
    }
    for (int i = 0; i < T; i++)
    {
        a = upiti[i];
        if (a <= 10)
        cout << a << endl;
        else if (a < 25)
         cout << 10 << endl;
        else if (a < 26)
            cout << 11 << endl;
        else if (a < 27)
            cout << 12 << endl;
        else if (a < 28)
            cout << 13 << endl;
        else if (a < 29)
            cout << 14 << endl;
        else if (a < 35)
            cout << 15 << endl;
        else if (a < 37)
            cout << 16 << endl;
        else if (a < 38)
            cout << 17 << endl;
        else if (a < 39)
            cout << 18 << endl;
        else if (a < 45)
            cout << 19 << endl;
        else if (a < 47)
            cout << 20 << endl;
        else if (a < 48)
            cout << 21 << endl;
        else if (a < 49)
            cout << 22 << endl;
        else if (a < 55)
            cout << 23 << endl;
        else if (a < 56)
            cout << 24 << endl;
        else if (a < 57)
            cout << 25 << endl;
        else if (a < 58)
            cout << 26 << endl;
        else if (a < 59)
            cout << 27 << endl;
        else if (a < 67)
            cout << 28 << endl;
        else if (a < 68)
            cout << 29 << endl;
        else if (a < 69)
            cout << 30 << endl;
        else if (a < 77)
            cout << 31 << endl;
        else if (a < 78)
            cout << 32 << endl;
        else if (a < 79)
            cout << 33 << endl;
        else if (a < 88)
            cout << 34 << endl;
        else if (a < 89)
            cout << 35 << endl;
        else if (a < 99)
            cout << 36 << endl;
        else if (a < 210)
            cout << 37 << endl;
        else if (a < 10001)
     cout << 300 << endl;
    }

    return 0;
}