St Andrews Online Judge

Clinical Tutorial Groups

By Kay Akashi

Time: 2000 ms
Memory: 256000 kB

The code judging system is only available during contests. Check out the github repo for test cases and solutions.

Please log in.

Problem Statement

Students in the School of Medicine are divided into several small clinical tutorial groups for clinical skills teaching. The groups are shuffled every year.

There're NN students in the School. You're given information as to "who was with who" as M1M_{1} pairs last year. Then, you're also given the same information of M2M_{2} pairs this year. Be noted that these information do not give you comprehensive lists of pairs (i.e. M1,M2N(N1)2M_{1}, M_{2} \leq \frac{N(N - 1)}{2}).

Amongst M2M_{2} pairs of clinical groups allocation this year, how many of them were the pairs of two students who were in the same group last year, according to the provided information?

Students are denoted as numbers 11, 22, …, NN. Suppose that there was no student who was added to or left the class during the transition of those two academic years.

Constraints

2N,M1,M21052 \leq N, M_{1}, M_{2} \leq 10^{5}

Input

The first line of input is a single integer, NN. The second line is a single integer, M1M_{1}. Then, M1M_{1} lines follow, each of each is shown by pp and qq (1p,qN1 \leq p, q \leq N, pqp \neq q) separated by a single blank space, indicating student pp and qq were in the same group last year. The (M1+3M_{1} + 3)-th line of input is a single integer, M2M_{2}. Then, M2M_{2} lines follow, each of each is shown by pp and qq (1p,qN1 \leq p, q \leq N, pqp \neq q) separated by a single blank space, indicating student pp and qq are in the same group this year.

Output

Answer the number of pairs amongst last M2M_{2} lines two of which were in the same group last year as well.

Examples

Input

6
6
1 2
2 5
5 2
3 4
4 6
6 3
4
3 1 
6 4
2 3 
1 2

Output

2

Explanation

66 students are divided into 22 groups. Last year, Group 11 had students 11, 22, and 55. Group 22 had students 33, 44, and 66. Now looking at this year's allocation, students 11 and 33 were not in the same group, so it doesn't add to the answer. Students 66 and 44 were both in the Group 22 last year, so there's one pair so far. Student 22 was in Group 11 while student 33 was in Group 22, so not same. Students 11 and 22 were both in Group 11, so it counts. Thus, the total number of pairs questioned is 22.

Input

7
3
1 3
3 4
2 5
5
1 4
6 7
7 5
5 2
5 3

Output

2

Explanation

In the first query, note that the pair information of students 11 and 44 was not directly mentioned in the first M1M_{1} queries, but they were in the same group last year. Thus it counts. In the second query, students 66 and 77 may have been in the same group last year, but since we don't have explicit evidence, it doesn't contribute to the final answer. In the third query, again any information about student 66 is unavailable, so we don't count it.

Input

10
6
4 9
10 9
3 8
3 5
7 5
2 6
3
1 7
7 8
2 4

Output

1