mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline def matmul(A, B): C = [[0] * len(B[0]) for _ 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 def matpow(A, p): n = len(A) B = [[0] * n for _ in range(n)] for i in range(n): B[i][i] = 1 while p > 0: if p & 1: B = matmul(B, A) A = matmul(A, A) p >>= 1 return B inv3 = pow(3, mod-2, mod) mat = [[0] * 6 for _ in range(6)] mat[0][0] = inv3 mat[0][4] = inv3 mat[0][5] = inv3 mat[1][1] = inv3 mat[1][3] = inv3 mat[1][5] = inv3 mat[2][2] = inv3 mat[2][3] = inv3 mat[2][4] = inv3 mat[3][0] = 1 mat[4][1] = 1 mat[5][2] = 1 vec = [[0] for _ in range(6)] vec[0][0] = 1 for _ in range(int(input())): N = int(input()) ans = matmul(matpow(mat, N), vec) print(ans[0][0]) if __name__ == '__main__': main()