T = int(input())
MOD = 10 ** 9 + 7
from collections import deque
for case in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    st = deque(A)
    while len(st) > 1:
        x = st.pop()
        y = st.pop()
        st.append((x + y + x * y) % MOD)
    ans = st.pop()
    print(ans)