#include #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll euler(map mp){ ll ret = 1; all(i, mp){ ret *= i.first - 1; ret *= modpow(i.first, i.second - 1, INF); } return ret; } map pridiv(ll n){ ll m = n; map mp; for(ll i=2;i*i<=m;i++){ while(n % i == 0){ n /= i; mp[i]++; } } if(n > 1) mp[n]++; return mp; } vector divisor(ll n){ vector v; for(ll i=1;i*i<=n;i++){ if(n % i == 0){ if(i * i != n) v.pb(n / i); v.pb(i); } } return v; } void solve(){ ll n, ans = INF; cin >> n; while(n % 2 == 0) n /= 2; while(n % 5 == 0) n /= 5; all(i, divisor(euler(pridiv(n)))) { ll num = modpow(10LL, i, n); if(num == 1 || num == 0) ans = min(ans, i); } cout << ans << endl; return; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); ll t; cin >> t; while(t--) solve(); return 0; }