Bridges

No attempts yetTime limit1sMemory limit256 MB

Problem

A river runs east-west with NN towns on the north bank (11 to NN) and NN on the south (N+1N+1 to 2N2N). On each bank, labels increase toward the east.

On the north bank, each town except NN has a one-way road to its eastern neighbor. On the south bank, each town except N+1N+1 has a one-way road to its western neighbor.

Roads may be permanently closed. Bridges connect one north town to one south town, work in both directions, never break, never cross, and each town uses at most one bridge.

Initially all roads are open and no bridges exist. Process MM events in order:

  • A G1 G2: build a bridge between G1G1 and G2G2.
  • B G1 G2: close the one-way road between G1G1 and G2G2.
  • Q G1 G2: ask whether G1G1 can reach G2G2 with current roads and bridges.

Input

Line 1: NN (1N1091 \le N \le 10^9) and MM (1M2000001 \le M \le 200\,000).

Next MM lines describe events. Town ids satisfy 1G1,G22N1 \le G1, G2 \le 2N and differ. Closed roads were open before; built bridges did not exist before.

Output

For each Q event, print DA if a route exists, otherwise NE, in input order.