Hide

Problem H
Swamp Paths

You live near a swamp with many precarious paths, and you try and keep an updated map of which paths are safe to use for yourself and others. Due to water level, weather, and other reasons sometimes paths are destroyed. Sometimes they become safe again, if the rainy season is over, etc.

Your map consists of $N$ locations numbered from $0$ to $N-1$ in the swamps along with some paths that directly connect pairs of locations. Each pair of locations will have at most one path between them and this path can be traversed in either direction (so a path from location $a$ to location $b$ is the same as a path from location $b$ to location $a$).

While you were on vacation, your neighbour monitored the swamp. Over time, they recorded when a path became safe or became unsafe. Every now and then, they recorded a query made by a visitor about whether a path was safe or not (though they did not record the result of that query).

Unfortunately, your neighbour lost the map of the region you maintained before you went on vacation! You do not remember the status of any paths when you left. But you do know a few things:

  • When your neighbour recorded that a path should be added, you know it was unsafe before the addition.

  • When your neighbour recorded that a path should be removed, you know it was safe before the removal.

You want to know the answer to each query that your neighbour recorded, this will give you a sense of how many visitors were able to enjoy walking along the paths in the swamp.

Input

The first line of input consists of the integers $N, L$ where $1 \le N, L \le 200\, 000$. Here, $N$ is the number of nodes in the swamp and $L$ is the number of entries in the log that your neighbour recorded.

Then $L$ lines follow, each describing a new entry in the log. These entries appear in the order they were added by your neighbour. A line for a log entry begins with one of the words QUERY, ADD, REMOVE followed by a pair of distinct integers $a, b$ ($0 \leq a < N, 0 \leq b < N$). They correspond to either a visitory querying a specific path, a path becoming safe, or it becoming unsafe respectively. The integers $a, b$ denote the pair of locations connected by the corresponding path. There will be at least one QUERY in the log.

Output

For each QUERY entry in the log, output a single line. If you can infer from the log that a path was safe or unsafe at the time of the query, output the corresponding text safe or unsafe. If you are unable to infer if the path was safe or unsafe at the time of the query then you should output the text unsure.

Sample Input 1 Sample Output 1
4 6
REMOVE 0 1
ADD 2 3
ADD 1 2
REMOVE 2 3
QUERY 1 2
QUERY 2 3
safe
unsafe
Sample Input 2 Sample Output 2
4 8
REMOVE 0 1
QUERY 1 2
REMOVE 1 2
QUERY 0 3
ADD 1 2
QUERY 2 1
ADD 1 3
QUERY 2 3
safe
unsure
safe
unsure
Sample Input 3 Sample Output 3
3 4
QUERY 0 1
ADD 0 1
REMOVE 0 1
QUERY 0 1
unsafe
unsafe

Please log in to submit a solution to this problem

Log in