def discrete_logarithm(a,b,MOD,permit0): a %= MOD; b %= MOD q = int(MOD**0.5)+2 # baby-step h = 1 if MOD != 1 else 0 memo = {} for i in range(q): if h==b and (permit0 or i): return i memo[h*b%MOD] = i h = h*a%MOD # giant-step #ここに来た時 h = a^q g = h for i in range(q): if g in memo: res = (i+1)*q-memo[g] if pow(a,res,MOD) == b: return res else: return -1 g = g*h%MOD return -1 #見つからない場合 T,*a = map(int,open(0).read().split()) for ai in a: while ai%2==0: ai//=2 while ai%5==0: ai//=5 print(discrete_logarithm(10,1,ai,0))