#include using namespace std; using ll = long long; ll modpow(ll a,ll n,ll p){ ll r=1; while(n>0){ if(n%2)r=(r*a)%p; a=(a*a)%p; n/=2; } return r; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll T; cin>>T; while(T--){ ll N,an=1e18; cin>>N; while(N%2==0)N/=2; while(N%5==0)N/=5; if(N==1){ cout<<1< P; ll CN=N; for(int p=2;p*p<=N;p++)if(N%p==0){ P.push_back(p); while(N%p==0)N/=p; } if(N!=1)P.push_back(N); N=CN; for(auto p:P){ N*=(p-1); N/=p; } for(ll p=1;p*p<=N;p++)if(N%p==0)for(ll e:{p,N/p})if(modpow(10,e,CN)==1)an=min(an,e); cout<