def mmult(A, B): global mod n, m, l = len(A), len(B), len(B[0]) ret = [[0] * l for _ in range(n)] for i in range(n): for j in range(m): for k in range(l): ret[i][k] = (ret[i][k] + A[i][j] * B[j][k]) % mod return ret def mpow(A, n): if n == 1: return A if n == 0: return [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))] return mmult(mpow(A, n - 1), A) if n % 2 else mpow(mmult(A, A), n // 2) mod = 10 ** 9 + 7 i3 = (mod + 1) // 3 X = [[i3, 0, 0, 0, i3, i3], [0, i3, 0, i3, 0, i3], [0, 0, i3, i3, i3, 0], [1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0]] T = int(input()) for _ in range(T): print(mpow(X, int(input()))[0][0])