MOD = 10**9 + 7 T = gets.to_i T.times do n = gets.to_i a = gets.split.map(&:to_i) until a.size == 1 x, y = a.pop(2) a << (x + y + x * y) % MOD end puts a[0] end