#include <bits/stdc++.h>
using namespace std;
int parent[100001];
long long sum[100001];
int freq[100001];
vector<vector<int>> v;
int find(int x)
{
if(x==parent[x]) return x;
x=find(parent[x]);
return x;
}
void add(int a, int b)
{
int x=find(a),y=find(b);
if(x==y) return;
vector<int> tv;
for(int temp=0;temp<v[x].size();temp++)
{
if(v[x][temp] != a) tv.push_back(v[x][temp]);
}
v[x].swap(tv);
if(v[x].size()!=0)
{
int leader=v[x][0];
freq[leader]=sum[leader]=0;
for(int temp=0;temp<v[x].size();temp++)
{
int node=v[x][temp];
parent[node]=leader;
freq[leader]++;
sum[leader]+=(long long) node;
}
if(leader!=x)
{
swap(v[x],v[leader]);
v[x].clear();
}
}
freq[y]++;
sum[y]+=(long long) a;
v[y].push_back(a);
parent[a]=y;
}
void unite(int a, int b)
{
int x=find(a),y=find(b);
if(x==y) return;
if(freq[y]>freq[x]) swap(x,y);
freq[x]+=freq[y];
sum[x]+=sum[y];
while(v[y].size()!=0)
{
int temp=v[y].back();
v[y].pop_back();
v[x].push_back(temp);
}
parent[y]=x;
}
int main()
{
int m,n,temp;
while(scanf("%d",&m)!=EOF)
{
scanf("%d",&n);
v.clear();
for(temp=1;temp<=m;temp++)
{
parent[temp]=temp;
sum[temp]=temp;
freq[temp]=1;
vector<int> t;
t.push_back(temp);
v.push_back(t);
}
for(temp=0;temp<n;temp++)
{
int key;
scanf("%d",&key);
int a,b;
if(key==1)
{
scanf("%d %d",&a,&b);
unite(a,b);
}
if(key==2)
{
scanf("%d %d",&a,&b);
add(a,b);
}
if(key==3)
{
scanf("%d",&a);
int x=find(a);
printf("%d %lld\n",freq[x],sum[x]);
}
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgcGFyZW50WzEwMDAwMV07CmxvbmcgbG9uZyBzdW1bMTAwMDAxXTsKaW50IGZyZXFbMTAwMDAxXTsKdmVjdG9yPHZlY3RvcjxpbnQ+PiB2OwoKaW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