By Kay Akashi
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 students in the School. You're given information as to "who was with who" as pairs last year. Then, you're also given the same information of pairs this year. Be noted that these information do not give you comprehensive lists of pairs (i.e. ).
Amongst 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 , , …, . Suppose that there was no student who was added to or left the class during the transition of those two academic years.
The first line of input is a single integer, . The second line is a single integer, . Then, lines follow, each of each is shown by and (, ) separated by a single blank space, indicating student and were in the same group last year. The ()-th line of input is a single integer, . Then, lines follow, each of each is shown by and (, ) separated by a single blank space, indicating student and are in the same group this year.
Answer the number of pairs amongst last lines two of which were in the same group last year as well.
6
6
1 2
2 5
5 2
3 4
4 6
6 3
4
3 1
6 4
2 3
1 2
2
students are divided into groups. Last year, Group had students , , and . Group had students , , and . Now looking at this year's allocation, students and were not in the same group, so it doesn't add to the answer. Students and were both in the Group last year, so there's one pair so far. Student was in Group while student was in Group , so not same. Students and were both in Group , so it counts. Thus, the total number of pairs questioned is .
7
3
1 3
3 4
2 5
5
1 4
6 7
7 5
5 2
5 3
2
In the first query, note that the pair information of students and was not directly mentioned in the first queries, but they were in the same group last year. Thus it counts. In the second query, students and 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 is unavailable, so we don't count it.
10
6
4 9
10 9
3 8
3 5
7 5
2 6
3
1 7
7 8
2 4
1