#P118. [KSC001D] A problem about charges

[KSC001D] A problem about charges

## Source

**This problem is adapted from [Long Long OJ](https://www.llong.tech/). All rights reserved by NOISG.**

**Problem source: <https://github.com/noisg/sg_noi_archive/tree/master/2019_prelim> (Task 3)**

**Materials compiled by [](/user/27).**

## Problem Description

There are $N$ charged particles. **Particles with opposite charges attract each other, while particles with the same charge repel each other.**

There are $Q$ operations, each represented as $T_i,A_i,B_i$, which can be divided into three types based on $T_i$:
- Operation $\tt A$ means $A_i$ and $B_i$ **attract** each other.
- Operation $\tt R$ means $A_i$ and $B_i$ **repel** each other.
- Operation $\tt Q$ asks what would happen if $A_i$ and $B_i$ are placed together, given the current information.

For each $\tt Q$ operation, if it is **determined that they attract**, output $\tt A$; if **determined that they repel**, output $\tt R$; if it cannot be determined, output $\tt ?$.

It is guaranteed that there is at least one possible configuration where all operations are consistent.

## Input Format

The first line contains two integers $N$ and $Q$.

The next $Q$ lines each contain a character $T_i$ and two integers $A_i,B_i$, representing an operation.

## Output Format

Several lines, each representing the answer to a $\tt Q$ operation.

## Samples

```input1
2 3
Q 1 2
R 1 2
Q 1 2
?
R
4 5
R 1 2
A 2 3
A 1 4
Q 2 4
Q 1 3
A
A

Sample 1 Explanation

For the first query, the relationship between 11 and 22 cannot be determined, so output ?\tt ?.

For the second query, it is determined that 11 and 22 repel each other, so output R\tt R.

Data Range

Subtask\text{Subtask} Points N,QN,Q Ti,Ai,BiT_i,A_i,B_i
00 77 N=2,Q10N=2,Q\le 10 None
11 1111 None Ai=1A_i=1 or Bi=1B_i=1
22 1414 TiT_i can only be R\tt R or Q\tt Q
33 1212 All queries occur after all relationships are given
44 2525 1N,Q1031\le N,Q \le 10^3 None
55 3131 None

For 100%100\% of the data:

  • 1N,Q1051 \le N,Q \le 10^5.
  • 1AiBiN1 \le A_i \neq B_i \le N.
  • TiT_i can only be A\tt A, R\tt R, or Q\tt Q.