#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; template T pow_ (T x, T n, T M){ uint64_t u = 1, xx = x; while (n > 0){ if (n&1) u = u * xx % M; xx = xx * xx % M; n >>= 1; } return static_cast(u); }; template vector divisor(T n){ vector ret; for(T i = 1; i * i <= n; i++) { if(n % i == 0) { ret.push_back(i); if(i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return(ret); } void solve(){ int x; cin >> x; while(x%2 == 0) x /= 2; while(x%5 == 0) x /= 5; if(x == 1) { puts("1"); return; } int phi = x, xx = x; for (int i = 2; i * i <= x; ++i) { if (xx % i == 0) { phi -= phi / i; while(xx % i == 0) xx /= i; } } if(xx > 1) phi -= phi/xx; for (auto &&i : divisor(phi)) { if(pow_(10, i, x) == 1){ cout << i << "\n"; return; } } } int main() { int t; cin >> t; while(t--){ solve(); } return 0; }