#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <cctype>
#include <cstdlib>
#include <iomanip>
#include <math.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int I_INF = INT_MAX;
const ll LL_INF = LLONG_MAX;
const ull ULL_INF = ULLONG_MAX;
bool mindmegven(bool volt[])
{
for (int i = 0; i <= 9; i++)
if (not volt[i])
return false;
return true;
}
void voltba_teves(ull n , bool volt[])
{
string s;
s = to_string(n);
for (int i = 0; i <= 9; i++)
{
char ch = i + '0';
int poz = s.find( ch);
if (poz != -1 && not volt[i])
{
volt[i] = true;
}
}
}
void solve()
{
ull n;
cin>> n;
bool volt[10] = { false };
bool ok = false;
int k = 2;
int db = 0;
ull tobbszoros = n;
while (!ok)
{
db++;
voltba_teves(tobbszoros, volt);
ok = mindmegven(volt);
tobbszoros = n * k;
k++;
}
cout << db << endl;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}