using System; using System.Collections.Generic; using System.IO; using static System.Console; using static System.Decimal; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); Dictionary L; int zero, one, two, three, seven, ten; decimal h, m, mod; void solve() { L = new Dictionary(); one = (int)One; two = (int)Add(one, one); three = (int)Add(one, two); seven = (int)Add(three, (int)Add(two, two)); ten = (int)Add(seven, three); h = Multiply(ten, ten); m = Multiply(h, h); mod = Add(Multiply(Multiply(m, m), ten), seven); L[zero] = two; L[one] = one; L[two] = three; int T = cin.scanint[zero]; for (int i = zero; i < T; i = (int)Add(i, one)) { WriteLine(calc(cin.scanint[zero])); } } decimal calc(int X) { if (L.ContainsKey(X)) return L[X]; Math.DivRem(X, two, out long r); if (r == zero) { var t = decimal.Multiply(calc(X >> one), calc(X >> one)); Math.DivRem(X >> one, two, out r); if (r == one) { t = Add(t, two); } else { t = Subtract(t, two); } return L[X] = Remainder(t, mod); } else { var t = Add(Subtract(calc((int)Add(X, one)), calc((int)Subtract(X, one))), mod); return L[X] = Remainder(t, mod); } } } class Scanner { public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } }