#P14023. [ICPC 2024 Nanjing R] 社交媒体

[ICPC 2024 Nanjing R] 社交媒体

Description

On a social media platform, users can leave comments under others' posts to express their thoughts. However, these comments are not visible to everyone. Specifically, for user CC to see user AA's comments under user BB's post, he/she has to be friends with both AA and BB at the same time. If a user leaves a comment under his/her own post, all his/her friends can see this comment.

As an active user on this platform, you would like to see as many comments as possible. There are kk users (not counting you) on the platform, numbered from 11 to kk. There are also mm comments on the platform, but you might not be able to see them all because you only have nn friends. As you need to participate in the 2024 ICPC Asia Nanjing Regional Contest, you don't have time to make too many new friends. What's the maximum number of comments you can see if you make at most two new friends on the platform?

Input Format

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains three integers nn, mm, and kk (1nk2×1051 \le n \le k \le 2 \times 10^5, 1m2×1051 \le m \le 2 \times 10^5) indicating the number of your friends, the number of comments, and the number of users (not counting you) on the platform.

The second line contains nn distinct integers f1,f2,,fnf_1, f_2, \cdots, f_n (1fik1 \le f_i \le k) indicating your friends on the platform.

For the following mm lines, the ii-th line contains two integers aia_i and bib_i (1ai,bik1 \le a_i, b_i \le k) indicating a comment written by user aia_i under user bib_i's post.

It's guaranteed that neither the sum of kk nor the sum of mm of all test cases will exceed 2×1052 \times 10^5.

Output Format

For each test case, output one line containing one integer, indicating the maximum number of comments you can see if you make at most two new friends on the platform.

5
4 12 7
5 7 3 6
3 6
2 2
1 4
2 4
1 3
7 6
4 1
5 4
1 1
1 1
2 1
3 7
2 7 6
2 4
1 2
3 2
2 5
5 4
2 6
4 6
2 6
1 1 2
1
1 2
2 1 2
1 2
1 2
2 1 100
24 11
11 24
9
5
1
1
1

Hint

For the first sample test case, you can make friends with user 11 and 44.

For the second sample test case, you can make friends with user 55 and 66.

For the third sample test case, you can make friends with user 22.

For the fourth and fifth sample test cases, you don't need to make new friends because you can already see all comments.