#include using namespace std; map res; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, t; cin >> t; while (t--) { cin >> n; while (1) { if (n % 2 != 0) break; n /= 2; } while (1) { if (n % 5 != 0) break; n /= 5; } if (n == 1) { cout << 1 << '\n'; } else { if (res.find(n) == res.end()) { int val = 1; for (int i = 1; ; i++) { val *= 10; val %= n; if (val == 1) { res[n] = i; break; } } cout << res[n] << '\n'; } else { cout << res[n] << '\n'; } } } return 0; }