#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; } ll beki[10010]; 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; } ll now = 1; for (int i = 0; i < 2010; i++) { beki[i] = now; now *= 10; now %= 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 (beki[p] == 1) { cout << p << endl; break; } } } return 0; }