#include <stdio.h> #include <string.h> #include <algorithm> using namespace std;
const int MAX_N = 100010; int nSets[MAX_N]; int nDis[MAX_N];
int nN, nM;
void MakeSets(int nNum) { for (int i = 0; i < nNum; ++i) { nSets[i] = i; nDis[i] = 0; } }
int FindSet(int nI) { if (nSets[nI] != nI) { int nPre = nSets[nI]; nSets[nI] = FindSet(nSets[nI]); nDis[nI] = (nDis[nI] + nDis[nPre]) % 2; } return nSets[nI]; }
void UnionSet(int nI, int nJ) { int nA = FindSet(nI); int nB = FindSet(nJ); if (nA != nB) { nSets[nA] = nB; nDis[nA] = (nDis[nI] + nDis[nJ] + 1) % 2; } }
int main() { int nT;
scanf("%d", nT); while (nT--) { scanf("%d%d", nN, nM); MakeSets(nN); char szOper[10]; int nA, nB; while (nM--) { scanf("%s%d%d", szOper, &nA, &nB); if (szOper[0] == 'D') { UnionSet(nA, nB); } else { int nX = FindSet(nA); int nY = FindSet(nB); if (nX == nY) { if (nDis[nA] == nDis[nB]) { printf("In the same gang.\n"); } else { printf("In different gangs.\n"); } } else { printf("Not sure yet.\n"); } } } }