FAVSUBS - Favorite Sub Hair

no tags 

Little Princess Rapunzel is blessed with long (really looong!) hair, which is golden colored and has healing power. After the end of a long happy story, she marries her lover Flynn. They decide to lead a normal life by getting rid of the mysterious hair, which when cut loses its power and turns brown. There are many colorful beads on her hair in order. Rapunzel has some K favorite colors B[1...K]

To remember good old stories, she wants to keep a part of her hair after its cut. A favorite sub hair is that continuous part of the hair, which has each of her favorite color beads at least once.

For the purpose of this problem, we represent a color as an integer and Hair as an array A[1...N], which has exactly N colored beads in the given order. Could you please tell her the total number of ways she can cut her favorite sub hair (sub-array). Two sub-arrays are different, if their starting or ending index in A differ.

Input

First line contains T [ number of test cases, around 10 ]. Each test case is preceded by a blank line, including the 1st case. [ -2,000,000 <= A[i], B[j] ( colors ) <= 2,000,000 ]
Each test case has 4 lines, as described below.
N [ 1 <= N <= 100,000 ]
< Array A : N integers, separated by spaces >
K [ 1 <= K <= 1,000 ]
< Array B : K integers, separated by spaces, her favorite colors, without repetition >

Output

For each test case, output the number of different sub-arrays, which has her favorite color appearing at least once, in a separate line.

Example

Input:
3

4
1 2 3 1
2
1 2

6
10 20 30 40 50 60
1
20

5
1 2 3 4 5
2
2 6

Output:
4
10
0

Explanation:

Case 1 : Favorite sub-arrays in bold [ 1 2 3 1 ], [ 1 2 3 1 ], [ 1 2 3 1 ], [ 1 2 3 1 ]

Note: Large input, prefer using scanf / printf to cin / cout

There are multiple test sets, and the judge shows the sum of the time taken over all test sets of your submission, if Accepted.



Added by:Anil Kishore
Date:2011-02-25
Time limit:0.306s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:CodeMutants 2011 , DA-IICT, India