mod = 10**9 + 7 for cas in xrange(input()): n, m, x, y = map(int, raw_input().strip().split()) a = map(int, raw_input().strip().split()) a += [0,0] coeff = [1] for i in xrange(m): coeff.append((coeff[-1] * 3 - 1) % mod) def f(m,x): t = 0 i = 0 while 1<<m <= x: t += a[i]*coeff[m] + a[i+1]*(coeff[m]-1) t %= mod i += 1 x -= 1<<m l = a[i] r = a[i+1] while m > 0: m -= 1 if 1<<m <= x: t += l*coeff[m] + (l+r)*(coeff[m]-1) t %= mod l += r x -= 1<<m else: r += l return t print (f(m,y) - f(m,x-1)) % mod