#include using namespace std; template using pv=vector>; template using matrix=vector>; template using pque=priority_queue; template using lpque=priority_queue,greater>; using ll=long long; using intpair=pair; using llpair=pair; using ilpair=pair; using lipair=pair; using intvec=vector; using llvec=vector; using intq=queue; using llq=queue; using intmat=vector; using llmat=vector; #define PI 3.141592653589793 #define INTINF ((1<<30)-1) #define LLINF 1LL<<60 #define MPRIME 1000000007 #define MPRIME9 998244353 #define MMPRIME (1ll<<61)-1 #define len length() #define pushb push_back #define fi first #define se second #define all(name) name.begin(),name.end() #define rall(name) name.rbegin(),name.rend() #define gsort(vbeg,vend) sort(vbeg,vend,greater<>()) template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline void init(T& v) { for(auto &a: v) cin>>a; } template inline void init(vector>& v) { for(auto &a: v) cin>>a.first>>a.second; } template inline void init(T& v, N n) { v.resize(n); for(auto &a: v) cin>>a; } template inline void init(vector>& v, N n) { v.resize(n); for(auto &a: v) cin>>a.first>>a.second; } template inline void out(T a) { cout< inline void out(T a, U... alist) { cout<(alist)...); } template void resiz(N n) { //empty } template void resiz(N n, T&& hd, U&&... tl) { hd.resize(n); resiz(n,forward(tl)...); } ll binpow(ll a, ll ex, ll p) { ll result=1; while(ex>0) { if(ex&1) result=result*a%p; ex>>=1; a=a*a%p; } return result; } struct Union_Find { private: vector parent; vector num; int treenum; public: Union_Find(int n) : parent(n),num(n,1) { treenum=n; for(int i=0; i>N>>M; } void solve() { Union_Find uf(N+1); for(int i=0; i>A>>B; int Asize=uf.size(A), Bsize=uf.size(B); if(Asize>Bsize || (Asize==Bsize && uf.root(A)