#include #include #include #define int long long using namespace std; int powmod(int a, int n, int mod) { if (n == 0) return 1; if (n % 2 == 1) return a * powmod(a, n - 1, mod) % mod; return powmod((a * a) % mod, n / 2, mod); } signed main() { int T; cin >> T; while (T--) { int n; cin >> n; vector yaku; for (int x = 1; x * x <= n; x++) { if (n % x == 0) { yaku.push_back(x); if (x * x != n) yaku.push_back(n / x); } } sort(yaku.begin(), yaku.end()); yaku[0] = 2; int C = 1000; int m1 = powmod(10, C + 1, n); for (int i = 0; i < yaku.size(); i++) { if (powmod(10, C + yaku[i], n) == m1) { cout << yaku[i] - 1 << endl; break; } } } return 0; }