#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; int get_period(int n) { map mymap; map::iterator it; int rem = 1, i = 1; while (true){ rem = (10*rem) % n; it = mymap.find(rem); if (it != mymap.end()) return (i - it->second); mymap[rem] = i; i++; } return -1; } void solve(){ int N; cin >> N; cout << get_period(N) << endl; } int main(){ int t; cin >> t; rep(i,t){ solve(); } return 0; }