Roommate

No attempts yetTime limit1sMemory limit128 MB

Problem

Two college students, Ji-Sung and Young-Pyo, are roommates sharing one dormitory room. Because they have lived together for a long time, they also share household appliances such as a hair dryer, an electric iron, and a battery charger. An appliance can be used by only one person at a time, so whenever both of them want the same appliance, their usage intervals must not overlap.

There are nn shared appliances, numbered from 11 to nn. Using appliance ii once takes Ji-Sung pip_i time units and Young-Pyo qiq_i time units.

On a given day, Ji-Sung wants to use appliances in the exact order oi1,oi2,,oiαo_{i_1}, o_{i_2}, \dots, o_{i_\alpha}, and Young-Pyo in the exact order oj1,oj2,,ojβo_{j_1}, o_{j_2}, \dots, o_{j_\beta}. The same appliance may appear several times in a sequence. Each person can start the next appliance in their own sequence only after finishing the current one, but the two people act independently and may use different appliances at the same time. When both need the same appliance, one of them has to wait until the other is done.

Find the earliest time by which both of them can finish their entire sequences.

Worked example: suppose there are 33 appliances, taking Ji-Sung 1,2,11, 2, 1 time units and Young-Pyo 2,1,32, 1, 3 time units respectively. Ji-Sung uses them in the order o1,o3,o1,o2o_1, o_3, o_1, o_2 and Young-Pyo in the order o1,o2,o1,o3o_1, o_2, o_1, o_3. An optimal schedule finishes at time 88.

Ji-Sung:

Young-Pyo:

Input

The input is read from standard input. The first line contains the number of test cases TT. Each test case consists of the following six lines.

  • Line 1: an integer nn (1n501 \le n \le 50), the number of appliances.
  • Line 2: nn integers, where the ii-th value is pip_i (1pi1001 \le p_i \le 100), the time Ji-Sung needs for appliance ii.
  • Line 3: nn integers, where the ii-th value is qiq_i (1qi1001 \le q_i \le 100), the time Young-Pyo needs for appliance ii.
  • Line 4: two integers α\alpha and β\beta (1α,β3001 \le \alpha, \beta \le 300), the lengths of the two usage sequences.
  • Line 5: α\alpha integers between 11 and nn, Ji-Sung's appliance sequence in order.
  • Line 6: β\beta integers between 11 and nn, Young-Pyo's appliance sequence in order.

Output

Write to standard output. For each test case, print on its own line the minimum time by which both Ji-Sung and Young-Pyo finish using all of their appliances.