#include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair; const ll INF = (1LL << 61); ll mod = 998244353; vector

prime_factorize(ll N) { vector

res; for (ll a = 2; a * a <= N; a++) { if (N % a != 0)continue; ll ex = 0; while (N % a == 0) { ex++; N /= a; } res.push_back({ a,ex }); } if (N != 1)res.push_back({ N, 1 }); return res; } vector enum_divisors(ll N) { vector res; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { res.push_back(i); if (N / i != i)res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } struct mint { ll x; // typedef long long ll; mint(ll x = 0) :x((x%mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } mint POW(mint n, int p) { if (p == 0)return 1; if (p % 2 == 0) { mint t = POW(n, p / 2); return t * t; } return n * POW(n, p - 1); } signed main() { ios::sync_with_stdio(false); cin.tie(0); ll T; cin >> T; for (int _ = 0; _ < T; _++) { ll N; cin >> N; while (N % 2 == 0)N /= 2; while (N % 5 == 0)N /= 5; if (N == 1) { cout << 1 << endl; continue; } mod = N; ll phi = N; for (auto p : prime_factorize(N)) { phi *= (p.first - 1); phi /= p.first; } vector a = enum_divisors(phi); for (auto p : a) { if (POW(10, p).x == 1) { cout << p << endl; break; } } } return 0; }