Problem: You are given n positive integers a1, a2, ..., an.

For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.

Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.

Input

The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.

Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).

Output

Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.

It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.

Examples

Input

2
8
2


Output

3
1


Input

2
3
4857


Output

5
20

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
clock_t __stt;
inline void TStart() { __stt = clock(); }
inline void TReport() {
  printf("\nCurrent Case Taken Time : %.3lf sec\n",
         (double)(clock() - __stt) / CLOCKS_PER_SEC);
}
template <typename T>
T MIN(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
T MAX(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
T ABS(T a) {
  return a > 0 ? a : (-a);
}
template <typename T>
void UMIN(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
void UMAX(T &a, T b) {
  if (b > a) a = b;
}
long long P, Q, M, pow5[25];
int d, n;
long long phi5(int e) { return pow5[e] - pow5[e] / 5ll; }
long long slowmul(long long A, long long B, long long M) {
  long long R = 0ll;
  while (B) {
    if (B & 1ll) {
      R = R + A;
      if (R >= M) R -= M;
    }
    B >>= 1ll;
    A *= 2ll;
    if (A >= M) A -= M;
  }
  return R;
}
long long powM(long long V, long long T, long long M) {
  long long R = 1ll;
  V %= M;
  while (T) {
    if (T & 1ll) R = slowmul(R, V, M);
    T >>= 1ll;
    V = slowmul(V, V, M);
  }
  return R;
}
void exgcd(long long A, long long B, long long &X, long long &Y) {
  if (!B) {
    X = 1ll;
    Y = 0ll;
    return;
  }
  exgcd(B, A % B, X, Y);
  swap(X, Y);
  Y -= X * (long long)(A / B);
}
long long inv(long long A, long long M) {
  long long X, K;
  exgcd(A, M, X, K);
  if (X < 0ll) {
    long long d = (-X + M - 1ll) / M;
    X += d * M;
  }
  return X % M;
}
map<long long, int> mp;
int BSGS(long long X, long long B, long long M, int BND) {
  int i, j, k, S, res;
  mp.clear();
  for (S = 1; S * S <= BND; ++S)
    ;
  long long cur = 1ll, itr = 1ll;
  for (i = 0; i < S; ++i) {
    mp[cur] = i;
    cur = slowmul(cur, B, M);
  }
  cur = inv(cur, M);
  for (res = 0;; res += S, itr = slowmul(itr, cur, M)) {
    long long T = slowmul(X, itr, M);
    if (mp.count(T)) {
      return res + mp[T];
    }
  }
}
void solve() {
  int i, j, k;
  scanf("%lld", &P);
  pow5[0] = 1ll;
  for (i = 1; i < 25; ++i) pow5[i] = pow5[i - 1] * 5ll;
  Q = P;
  for (d = 0; Q; Q /= 10ll, ++d)
    ;
  M = 1ll;
  for (n = 0;; ++n) {
    long long x = P * M, L = 1ll << (long long)(n + d), Y;
    Q = (L - x % L) % L;
    while (Q < M && !((x + Q) % 5ll)) {
      Q += L;
    }
    if (Q >= M) {
      M *= 10ll;
      continue;
    }
    Y = (x + Q) / L;
    long long nk = 0ll;
    for (i = 1; i <= n + d; ++i) {
      long long B = powM(2, phi5(i - 1), pow5[i]);
      long long X =
          slowmul(Y % pow5[i], inv(powM(2, nk, pow5[i]), pow5[i]), pow5[i]);
      nk += BSGS(X, B, pow5[i], 5) * phi5(i - 1);
    }
    printf("%lld\n", nk + (long long)n + (long long)d);
    return;
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}