100 atcoder#ABC190C. [ABC190C] Bowls and Dishes

[ABC190C] Bowls and Dishes

Score : 300300 points

Problem Statement

We have NN dishes numbered 1,2,,N1, 2, \dots, N and MM conditions numbered 1,2,,M1, 2, \dots, M. Condition ii is satisfied when both Dish AiA_i and Dish BiB_i have (one or more) balls on them. There are KK people numbered 1,2,,K1, 2, \dots, K. Person ii will put a ball on Dish CiC_i or Dish DiD_i. At most how many conditions will be satisfied?

Constraints

  • All values in input are integers.
  • 2N1002 \leq N \leq 100
  • 1M1001 \leq M \leq 100
  • 1Ai<BiN1 \leq A_i < B_i \leq N
  • 1K161 \leq K \leq 16
  • 1Ci<DiN1 \leq C_i < D_i \leq N

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

\vdots

AMA_M BMB_M

KK

C1C_1 D1D_1

\vdots

CKC_K DKD_K

Output

Print the answer.

4 4
1 2
1 3
2 4
3 4
3
1 2
1 3
2 3
2

For example, if People 1,2,31, 2, 3 put their balls on Dishes 1,3,21, 3, 2, respectively, Conditions 11 and 22 will be satisfied.

4 4
1 2
1 3
2 4
3 4
4
3 4
1 2
2 4
2 4
4

For example, if People 1,2,3,41, 2, 3, 4 put their balls on Dishes 3,1,2,43, 1, 2, 4, respectively, all conditions will be satisfied.

6 12
2 3
4 6
1 2
4 5
2 6
1 5
4 5
1 3
1 2
2 6
2 3
2 5
5
3 5
1 4
2 6
4 6
5 6
9