mod = 10**9 + 7 t = int(input()) for _ in range(t): s = 0 a = [int(v) for v in input().split()] for v in a: s = (s + a + s * a) % mod print(s)