Matei, an esteemed student from the National High School of Computer Science in Piatra Neamț, is now studying in Bucharest. Hearing that the IIOT finals will take place in his hometown, he wants to make sure he doesn't miss out on the event!
The road network of Moldova and Muntenia can be modeled as a directed graph with vertices (cities) and edges (roads). The road network is in severe disrepair, so the government recently approved the construction of several new roads. The roads will be constructed in the following ways:
- — Constructs a new road from city to every city in the interval .
- — Constructs a new road from every city in the interval to city .
- — Constructs a new road between every pair of cities within the interval .
Task
Seeing the new road network, Matei wonders about the following question: how many pairs of cities are there such that both paths from and exist?
Input data
The first line of the input contains two space-separated integers, and , where represents the number of cities in the network and the number of initial roads.
The following lines each contain two space-separated integers, and , representing a road from city to city in the original network.
The following line contains the integer , the number of new construction phases.
The next lines describe the construction phases. Each line begins with an integer , followed by additional space-separated integers corresponding to the parameters of the construction type described above.
Output data
The first line of the output must contain a single integer representing the total number of pairs for which both directed paths and exist in the final network.
Constraints and clarifications
- for every road in the network.
- for every construction phase.
| # | Score | Constraints |
|---|---|---|
| 0 | 0 | Examples |
| 1 | 10 | |
| 2 | 8 | |
| 3 | 12 | All construction phases are of . |
| 4 | 15 | , for all construction phases of , we guarantee that . |
| 5 | 55 | No further restrictions. |
Example
stdin
5 4
1 2
2 3
3 4
4 5
1
3 1 5
stdout
25