MOD = 10 ** 9 + 7 def solve(N, A): res = A[0] for a in A[1:]: res = res * a + res + a res %= MOD return res T = int(input()) for _ in range(T): N = int(input()) A = tuple(map(int, input().split())) print(solve(N, A))