#include using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } // オイラーのトーシェント関数 // yukicoder No.1339 template T euler_phi(T n){ T res=n; for(T i=2;i*i<=n;++i){ if(n%i==0){ res-=res/i; while(n%i==0)n/=i; } } if(n>1)res-=res/n; return res; } // 約数はソートしていないことに注意 template vector divisor(T n){ vector res; for(T i=1;i*i<=n;++i){ if(n%i==0){ res.emplace_back(i); if(i!=n/i)res.emplace_back(n/i); } } return res; } ll mod_pow(ll x,ll n,ll Mod){ x%=Mod; ll res=1; while(n>0){ if(n&1LL)res=res*x%Mod; x=x*x%Mod; n>>=1LL; } return res; } int solve(int n){ while(n%2==0)n/=2; while(n%5==0)n/=5; int res=n; for(int d:divisor(euler_phi(n))){ if(mod_pow(10,d,n)==1){ res=min(res,d); } } return res; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while(q--){ int n; cin >> n; cout << solve(n) << "\n"; } }