import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # A*B def mat_mul(A, B, mod): C = [[0]*len(B[0]) for i in range(len(A))] for i in range(len(A)): for k in range(len(B)): for j in range(len(B[0])): C[i][j] = (C[i][j] + A[i][k]*B[k][j])%mod return C #A**n def mat_pow(A, n, mod): B = [[0]*len(A) for i in range(len(A))] for i in range(len(A)): B[i][i] = 1 while n > 0: if n & 1 == 1: B = mat_mul(A, B, mod) A = mat_mul(A, A, mod) n = n>>1 return B mod = 10**9+7 p = pow(3, mod-2, mod) A = [[p,0,0,0,p,p],[0,p,0,p,0,p],[0,0,p,p,p,0],[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0]] X = [p, 0, 0, 1, 0, 0] t = int(input()) for _ in range(t): n = int(input()) M = mat_pow(A, n-1, mod) ans = 0 for j in range(6): ans += M[0][j]*X[j] ans %= mod print(ans)