from sys import stdin def matdot(a,b,mod): matsize = len(a) val = [[0 for i in range(matsize)] for j in range(matsize)] for i in range(matsize): for j in range(matsize): for k in range(matsize): val[i][j] = (val[i][j] + a[i][k] * b[k][j]) % mod return val def powmodmat(n,pow,mod): matsize = len(n) val = [[0 for i in range(matsize)] for j in range(matsize)] for i in range(matsize): val[i][i] = 1 while pow > 0: if pow & 1: val = matdot(val, n, mod) pow = pow >> 1 n = matdot(n, n, mod) return val t, *a = map(int, stdin.read().split()) p = 10**9+7 inv3 = (p+1) // 3 mat = [[inv3,0,0,0,inv3,inv3],[0,inv3,0,inv3,0,inv3],[0,0,inv3,inv3,inv3,0],[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0]] for i in range(t): kari = powmodmat(mat,a[i],p) print(kari[0][0])