Monk has recently created a matrimonial site. X men and Y women registered there. As Monk has access to everyone's Facebook profile, he can see whether a person is a friend of another person or not. He doesn't want any two people who are in a single group to get married together. So, first we have q1 relationships among men. Then, we have q2 relationships among women. Finally we have q3 relationships among men and women. Read the input format for more clarity. Now, Monk wants to calculate the total number of unique marriages he can set between men and women provided the conditions are followed.
Note - Two person are said to be in a group if they are friends directly or connected through a chain of mutual friends.
Input:
The first line consists of X and Y.
Next line consists of variable q1.
The next q1 lines will have two integers of the form A B where A and B are both men and are friends on facebook and A≠B.
Next line consists of variable q2.
The next q2 lines will have two integers of the form A B where A and B are both women and are friends on facebook and A≠B.
Next line consists of variable q3.
The next q3 lines will have two integers of the form A B where A is a man and B is a woman and they both are friends on facebook.
Output:
Print in a single line the answer.
Constraints:
1≤X,Y≤106
1≤q1,q2,q3≤106
If A is a man, then 1≤A≤X
If A is a woman, then 1≤A≤Y
If B is a man, then 1≤B≤X
If B is a woman, then 1≤B≤Y
In the sample test case, there are 4 groups.
Group1−Man1,Man3,Woman2
Group2−Man4,Woman1,Woman4,Woman5
Group3−Man2
Group4−Woman3
The men in Group1 can marry 4 women = 8 possibilities
The single man in Group2 can marry 2 women = 2 possibilities
The single man in Group3 can marry 5 women = 5 possibilities