#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(),(x).end() #define inf 1e18 #define mod 1000000007 using namespace std; typedef long long llint; typedef long long ll; typedef pair P; ll T; ll n; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> T; while(T--){ cin >> n; while(n % 5 == 0) n /= 5; while(n % 2 == 0) n /= 2; if(n == 1){ cout << 1 << endl; continue; } ll ans = 1, x = 9; while(x % n){ ans++; x = (x*10+9) % n; } cout << ans << endl; } return 0; }