#!/usr/bin/python
import numpy as np;
from scipy.signal import *;
import sys

def process_testcase():
  sys.stdin.readline()
  t = int(sys.stdin.readline())
  text = [int(x) for x in sys.stdin.readline().strip().split()]
  
  p1 = int(sys.stdin.readline())
  pattern1 = [int(x) for x in sys.stdin.readline().strip().split()]

  p2 = int(sys.stdin.readline())
  pattern2 = [int(x) for x in sys.stdin.readline().strip().split()]

  tt = []
  pp1 = []
  pp2 = []

  for x in text:
    tt.append(0)
    for i in xrange(0, x-1):
      tt.append(1)

  tt.append(0)

  for x in pattern1:
    pp1.append(1)
    for i in xrange(0, x-1):
      pp1.append(0)

  pp1.append(1)
  pp1.reverse()

  for x in pattern2:
    pp2.append(1)
    for i in xrange(0, x-1):
      pp2.append(0)

  pp2.append(1)
  pp2.reverse()

  c1 = fftconvolve(np.array(tt), np.array(pp1))
  c2 = fftconvolve(np.array(tt), np.array(pp2))

  m1 = []
  pos = 0
  out1 = 0
  for x in c1:
    pos += 1
    if pos >= len(pp1) and len(tt) - pos >= 0:
      if x <= 0.0001:
        out1 += 1
        m1.append(1)
      else:
        m1.append(0)

  pos = 0
  out2 = 0
  m2 = []
  for x in c2:
    pos += 1
    if pos >= len(pp2) and len(tt) - pos >= 0:
      if x <= 0.0001:
        out2 += 1
        m2.append(1)
      else:
        m2.append(0)

  m2.reverse()
  ma = 0
  mapos = 0

  if len(m1) > 0 and len(m2) > 0:
    c3 = fftconvolve(np.array(m1), np.array(m2))

    ind = 0
    for x in c3:
      val = int(x+0.001)
      pos = len(tt) - ind - len(pp2) - len(pp1) + 1
      ind+=1
      if pos > len(tt):
        continue
      if pos <= 0:
        continue
      if val > ma:
        ma = val
        mapos = pos
      elif val == ma and pos < mapos:
        mapos = pos


  print "%d %d %d %d" % (out1, out2, mapos, ma)
  sys.stdout.flush()

testcases = int(sys.stdin.readline())

for testcase_num in xrange(0, testcases):
  process_testcase()
