#include<iostream> using namespace std; const int maxn = 30000+100; int F[maxn], D[maxn], S[maxn]; void set(int n) { for(int i =0 ;i < n; i++) { F[i] = i; D[i] = 0; S[i] = 1; } } void find(int x) { if(x != F[x]) { find(F[x]); D[x]+= D[F[x]]; F[x] = F[F[x]]; } } void Union(int x, int y) { find(x);find(y); x = F[x]; y= F[y]; F[x] = y; D[x] = S[y]; S[y] += S[x]; } int main() { set(maxn); int P; cin>>P; char c; int a, b; while(P--) { cin >> c; if(c=='M') { cin>> a >> b; Union(a, b); }else { cin>>a; find(a); cout << D[a] <<endl; } } return 0; }