#pragma GCC target ("avx2") // #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include using namespace std; using ll=long long; template using V = vector; template using P = pair; using vll = V; using vii = V; using vvll = V; using vvii = V< V >; using PII = P; using PLL = P; #define RevREP(i,n,a) for(ll i=n;i>a;i--) // (a,n] #define REP(i,a,n) for(ll i=a;i inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; } template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; } template< class A, class B > ostream& operator <<(ostream& out, const P &p) { return out << '(' << p.first << ", " << p.second << ')'; } template< class A > ostream& operator <<(ostream& out, const V &v) { out << '['; for (int i=0;i> 1, m); if (p & 1) return (tmp * tmp % m) * a % m; else return tmp * tmp % m; } void solve() { ll n; cin >> n; ll orign = n; while (orign % 2 == 0) orign /= 2; while (orign % 5 == 0) orign /= 5; if (orign == 1) { cout << 1 << '\n'; return; } ll phi = orign - 1; for (ll i = 2; i * i <= orign; i++) { if (orign % i == 0) { phi -= (orign / i == i ? 1 : 2); } } int ans = INF; for (ll i = 1; i * i <= phi; i++) { if (phi % i == 0) { if (powmod(10, i, orign) == 1) chmin(ans, int(i)); if (powmod(10, phi / i, orign) == 1) chmin(ans, int(phi / i)); } } cout << ans << '\n'; } int main() { cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; while (t-->0) { solve(); } return 0; }