/* author: Kite_kuma created: 2021.01.15 21:51:17 */ // #ifdef LOCAL // #define _GLIBCXX_DEBUG // #endif #include using namespace std; #pragma region macros #define foa(s, v) for(auto &s : v) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define popcnt(n) __builtin_popcountll((long long)n) #define REPname(a, b, c, d, e, ...) e #define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__) #define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro) #define REP1(i, x) for(int i = 0; i < (x); ++i) #define REP2(i, l, r) for(int i = (l); i < (r); ++i) #define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c)) #define DREPname(a, b, c, d, e, ...) e #define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__) #define DREP1(i, x) for(int i = (x)-1; i >= 0; --i) #define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i) #define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c)) #pragma endregion #pragma region aliases using ll = long long; using ld = long double; using ull = unsigned long long; using vb = vector; using vi = vector; using vvi = vector>; using vvvi = vector>>; using vll = vector; using vvll = vector; using vvvll = vector; using pii = std::pair; using pll = std::pair; template using V = vector; template using VV = V>; template using VVV = V>>; template using pqup = priority_queue, greater>; template using pqdn = priority_queue; #pragma endregion #pragma region constants const int inf = 1e9; const long long INF = 1e18; const long double pi = acos(-1); const char dl = '\n'; const char sp = ' '; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int mod = 1000000007; // const int mod = 998244353; #pragma endregion #pragma region basic_operation template inline bool in_range(T x, T lef, T rig) { return ((lef <= x) && (x < rig)); } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } void Yes(bool f = 1) { cout << (f ? "Yes" : "No") << '\n'; } void No() { cout << "No\n"; } void YES(bool f = 1) { cout << (f ? "YES" : "NO") << '\n'; } void NO() { cout << "NO\n"; } template void drop(T answer) { cout << answer << '\n'; exit(0); } void err(bool flag = true) { if(!flag) return; cout << -1 << '\n'; exit(0); } template void vout(vector const &v, bool tate = 0) { if(tate) { for(auto const &a : v) { cout << a << '\n'; } return; } for(auto it = v.begin(); it != v.end(); it++) { cout << (*it); if(it != v.end() - 1) { cout << ' '; } } cout << '\n'; return; } inline void print() { cout << '\n'; } template inline void print(T x) { cout << x << '\n'; return; } template void print(Head H, Tail... T) { cout << H << " "; print(T...); } template void add(vector &v, T val) { for(auto &a : v) a += val; return; } template T dup(T a, T b) { assert(b != 0); return (a + b - 1) / b; } template T greatest_lower_multiple(T x, T d) { if(d == 0) return 0; if(d < 0) d *= -1; T y = x % d; if(y < 0) y += d; return x - y; } template T least_upper_multiple(T x, T d) { return -greatest_lower_multiple(-x, d); } long long POW(long long a, long long n) { long long res = 1; while(n > 0) { if(n & 1) res = res * a; a = a * a; n >>= 1; } return res; } long long modpow(long long a, long long n, long long mod) { // a^n mod assert(n >= 0); if(mod == 1) return 0LL; long long res = 1; while(n > 0) { if(n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // return x such that a * x % mod == gcd(a, mod) // not (mod divides a) long long modinv(long long a, long long mod) { long long b = mod, u = 1, v = 0; while(b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if(u < 0) u += mod; return u; } // normal binomial coefficient vvll comb(100, vll(100, -1)); long long com(long long n, long long k) { assert(n < 100 && k < 100); if(n < k || k < 0 || n < 0) return 0; if(comb[n][k] != -1) return comb[n][k]; ll res; if(n - k < k) res = com(n, n - k); else if(k == 0) res = 1; else res = com(n - 1, k - 1) + com(n - 1, k); comb[n][k] = res; return res; } const int MAX = 5100000; // 300ms, when MAX = 3*10^7 : 1900ms long long fac[MAX], finv[MAX], inv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } long long commod(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } long long pmod(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[n - k] % mod; } // n個の区別しないボールを区別するk個の箱に入れる方法の総数 long long hmod(long long n, long long k) { // 重複組み合わせ return commod(n + k - 1, n); } template int lb(const std::vector &a, const T x) { return std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x)); } template int ub(const std::vector &a, const T x) { return std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x)); } template void unq(std::vector &a) { std::sort(a.begin(), a.end()); a.erase(std::unique(a.begin(), a.end()), a.end()); } template std::vector press(std::vector &a) { auto vec = a; unq(vec); std::vector ret; for(auto &v : a) ret.push_back(lb(vec, v)); return ret; } #pragma endregion #pragma region input #define VEC(type, name, size) \ vector name(size); \ scanner::INPUT(name) #define VVEC(type, name, h, w) \ vector> name(h, vector(w)); \ scanner::INPUT(name) #define INT(...) \ int __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define LL(...) \ long long __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define CHR(...) \ char __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define LD(...) \ long double __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) namespace scanner { template void scan(T &a) { cin >> a; } template void scan(vector &a) { for(auto &i : a) scan(i); } template void scan(pair &p) { scan(p.first); scan(p.second); } void INPUT() {} template void INPUT(Head &head, Tail &...tail) { scan(head); INPUT(tail...); } } // namespace scanner template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } #pragma endregion #pragma region debug #pragma region output template std::ostream &std::operator<<(std::ostream &os, const std::pair &p) { os << p.first << " " << p.second; return os; } template std::ostream &std::operator<<(std::ostream &os, const std::vector &v) { for(int i = 0; i < (int)v.size(); i++) { if(i) os << " "; os << v[i]; } return os; } #pragma endregion #pragma region view namespace viewer { template void view(const T e) { std::cerr << e; } template void view(const std::pair &p) { std::cerr << "("; view(p.first); std::cerr << ", "; view(p.second); std::cerr << ")"; } template void view(const std::set &s) { if(s.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(auto &t : s) { view(t); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::unordered_set &s) { if(s.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(auto &t : s) { view(t); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::vector &v) { if(v.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(const auto &e : v) { view(e); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::vector> &vv) { std::cerr << "{\n"; for(const auto &v : vv) { std::cerr << "\t"; view(v); std::cerr << '\n'; } std::cerr << "}"; } template void view(const std::vector> &v) { std::cerr << "{\n"; for(const auto &c : v) { std::cerr << "\t("; view(c.first); std::cerr << ", "; view(c.second); std::cerr << ")\n"; } std::cerr << "}"; } template void view(const std::map &m) { std::cerr << "{\n"; for(const auto &t : m) { std::cerr << "\t["; view(t.first); std::cerr << "] : "; view(t.second); std::cerr << '\n'; } std::cerr << "}"; } template void view(const std::unordered_map &m) { std::cerr << "{\n"; for(const auto &t : m) { std::cerr << "\t["; view(t.first); std::cerr << "] : "; view(t.second); std::cerr << '\n'; } std::cerr << "}"; } } // namespace viewer #pragma endregion // when debugging : g++ foo.cpp -DLOCAL #ifdef LOCAL void debug_out() {} template void debug_out(Head H, Tail... T) { viewer::view(H); std::cerr << ", "; debug_out(T...); } #define debug(...) \ do { \ std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \ debug_out(__VA_ARGS__); \ std::cerr << "\b\b]\n"; \ } while(0) #define dump(x) \ do { \ std::cerr << __LINE__ << " " << #x << " : "; \ view(x); \ std::cerr << '\n'; \ } while(0) #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #pragma endregion ll solve(int n) { while(n % 2 == 0) n /= 2; while(n % 5 == 0) n /= 5; if(n == 1) return 1LL; ll ans = 1LL; auto ok = [](int keta, ll MOD) { return modpow(10, keta, MOD) == 1; }; auto search = [&](ll d) { ll m = d - 1; ll ans = INF; rep(i, 1, m + 1) { if((ll)i * (ll)i > m) break; if(m % i == 0) { if(ok(i, d)) chmin(ans, (ll)i); if(ok(m / i, d)) chmin(ans, (ll)m / i); } } return ans; }; auto f = [&](ll d, ll cnt) -> ll { ll ret = INF; if(d == 3) { return POW(3, max(0LL, cnt - 2)); } ret = search(d); ret *= POW(d, cnt - 1); return ret; }; ll m = n; debug(m); rep(i, 2, m + 1) { if((ll)i * (ll)i > m) { break; } if(m % i == 0) { ll ret = i; ll cnt = 0; while(m % i == 0) { debug(m, i); m /= i; cnt++; } ll res = f(ret, cnt); ans = ans / __gcd(ans, res) * res; } } if(m > 1) { ll res = f(m, 1); ans /= __gcd(ans, res); ans *= res; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); srand((unsigned)time(NULL)); INT(t); rep(t) { int n; cin >> n; print(solve(n)); } return 0; }