Box and Arrow Diagram

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

An example of a box and arrow diagram, taken from github.com/dicander/box_arrow_diagram

What an embarrassment! Itaf got 0/5 points in her last "Fundamental programming in Python" exam. She studies Engineering physics at KTH and is struggling with this course. She is not alone, as 6060\\% of her classmates failed the exam this year. The reason for this oddly high percentage is the so called box and arrow diagram (låd- och pildiagram).

In this part of the exam you are given a piece of Python code and you have to draw how the memory structure will look like when the program reaches a given line. Since Itaf is a high-rated competitive programmer her ego always came in the way whenever she tried to study for the test, because it felt "too easy". But now she has become desperate and needs your help.

The box and arrow diagram is used to explain the memory structure inside Python. Simplified, the diagram can be seen as a directed graph with nodes (boxes) labeled from 11 to NN and edges (arrows) labeled from 11 to MM. The boxes corresponds to the objects in the memory of a Python program. Box 1 is special, it represents the global object. An arrow being drawn from box uu to box vv in the diagram means that object uu stores a reference of object vv. If uu stores multiple references of vv, then you draw multiple arrows from uu to vv. It is also possible for an object to contain references to itself.

An object uu is said to be alive if there exists a path from the global object to uu in the box and arrow diagram. Each object also has a reference counter. The reference counter of an object uu is defined as the number of arrows (v,u)(v,u) such that vv is alive.

Itaf now needs your help, and she will ask you QQ queries, each query can be one of two types.

  • 1 X Remove the arrow with label XX from the diagram.}
  • 2 Y Output the reference counter of the object with label YY.}

입력

The first line consists of two space separated integers N,MN,M (1N,M21051 \leq N,M \leq 2 \cdot 10^5), where NN is the number of boxes in the diagram and MM is the number of arrows in the diagram.

The next MM lines describe the arrows in the diagram. The ii-th line contains 22 space separated integers U_i,V_iU\_i,V\_i (1U_i,V_iN1 \leq U\_i,V\_i \leq N), meaning the arrow with label ii goes from box U_iU\_i to box V_iV\_i. Note that arrows forming loops and multi-edges are allowed.

The next line contains an integer QQ (1Q21051 \leq Q \leq 2 \cdot 10^5), the number of queries. The next QQ lines describe the QQ queries. The jj-th query is given as a pair of space separated integers C_j,X_jC\_j, X\_j (1C_j21 \leq C\_j \leq 2).

  • If C_j=1C\_j = 1 then remove the arrow labeled X_jX\_j from the diagram (1X_jM1 \leq X\_j \leq M).
  • If C_j=2C\_j = 2 then output the reference counter of object X_jX\_j (1X_jN1 \leq X\_j \leq N).

It is guaranteed that there will not be two queries of type 11 with same value of X_jX\_j, meaning the same arrow will never be deleted twice.

출력

For each query of type 22, output a single line containing the reference count of object Y_jY\_j.