import sys #input = sys.stdin.readline input = sys.stdin.buffer.readline def mat_dot(A, B, MOD=pow(10,9)+7): #A:n*m行列, B:m*l行列 n, m, l = len(A), len(A[0]), len(B[0]) X = [[0]*l for i in range(n)] for i in range(n): for j in range(l): temp = 0 for k in range(m): temp = (temp + A[i][k] * B[k][j]) % MOD X[i][j] = temp return X def mat_pow(A, x, MOD): #A^x n = len(A) X = [[0] * n for i in range(n)] for i in range(n): X[i][i] = 1 for i in range(x.bit_length()): if (x>>i)&1: X = mat_dot(X, A, MOD) A = mat_dot(A, A, MOD) return X def main(): T = int(input()); MOD = pow(10,9) + 7 inv3 = pow(3,MOD-2,MOD) X = [[inv3,0,0,1,0,0],[0,inv3,0,0,1,0],[0,0,inv3,0,0,1],[0,inv3,inv3,0,0,0],[inv3,0,inv3,0,0,0],[inv3,inv3,0,0,0,0]] for _ in range(T): N = int(input()) v = [[1],[0],[0],[0],[0],[0]] XN = mat_pow(X,N,MOD) g = mat_dot(XN,v,MOD) #print(XN) print(g[0][0]) if __name__ == '__main__': main()