#include <bits/stdc++.h>
using namespace std;
long long sum[100001];
int freq[100001];
int ingroup[100001];
int main()
{
int m,n,temp;
while(scanf("%d",&m)!=EOF)
{
scanf("%d",&n);
set<int> s[n+1];
for(temp=1;temp<=m;temp++)
{
ingroup[temp]=temp;
sum[temp]=temp;
freq[temp]=1;
s[temp].insert(temp);
}
for(temp=0;temp<n;temp++)
{
int key;
scanf("%d",&key);
int a,b;
if(key==1)
{
scanf("%d %d",&a,&b);
int x=ingroup[a],y=ingroup[b];
if(x==y) continue;
if(s[x].size()<s[y].size()) swap(x,y);
sum[x]+=sum[y];
freq[x]+=freq[y];
while(!s[y].empty())
{
auto it=s[y].begin();
int element=*it;
ingroup[element]=x;
s[x].insert(element);
s[y].erase(element);
}
}
if(key==2)
{
scanf("%d %d",&a,&b);
int x=ingroup[a],y=ingroup[b];
if(x==y) continue;
sum[x]-=a;
freq[x]--;
sum[y]+=a;
freq[y]++;
ingroup[a]=y;
s[x].erase(a);
s[y].insert(a);
}
if(key==3)
{
scanf("%d",&a);
int x=ingroup[a];
printf("%d %lld\n",freq[x],sum[x]);
}
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpsb25nIGxvbmcgc3VtWzEwMDAwMV07CmludCBmcmVxWzEwMDAwMV07CmludCBpbmdyb3VwWzEwMDAwMV07CgoKaW50IG1haW4oKQp7CiAgICBpbnQgbSxuLHRlbXA7CiAgICB3aGlsZShzY2FuZigiJWQiLCZtKSE9RU9GKQogICAgewogICAgICAgIHNjYW5mKCIlZCIsJm4pOwogICAgICAgIHNldDxpbnQ+IHNbbisxXTsKICAgICAgICBmb3IodGVtcD0xO3RlbXA8PW07dGVtcCsrKQogICAgICAgIHsKICAgICAgICAJaW5ncm91cFt0ZW1wXT10ZW1wOwogICAgICAgICAgICBzdW1bdGVtcF09dGVtcDsKICAgICAgICAgICAgZnJlcVt0ZW1wXT0xOwogICAgICAgICAgICBzW3RlbXBdLmluc2VydCh0ZW1wKTsKICAgICAgICB9CiAgICAgICAgZm9yKHRlbXA9MDt0ZW1wPG47dGVtcCsrKQogICAgICAgIHsKICAgICAgICAgICAgaW50IGtleTsKICAgICAgICAgICAgc2NhbmYoIiVkIiwma2V5KTsKICAgICAgICAgICAgaW50IGEsYjsKICAgICAgICAgICAgaWYoa2V5PT0xKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzY2FuZigiJWQgJWQiLCZhLCZiKTsKICAgICAgICAgICAgICAgIGludCB4PWluZ3JvdXBbYV0seT1pbmdyb3VwW2JdOyAKICAgICAgICAgICAgICAgIGlmKHg9PXkpCWNvbnRpbnVlOwogICAgICAgICAgICAgICAgaWYoc1t4XS5zaXplKCk8c1t5XS5zaXplKCkpCXN3YXAoeCx5KTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgc3VtW3hdKz1zdW1beV07CiAgICAgICAgICAgICAgICBmcmVxW3hdKz1mcmVxW3ldOwogICAgICAgICAgICAgICAgd2hpbGUoIXNbeV0uZW1wdHkoKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIAlhdXRvIGl0PXNbeV0uYmVnaW4oKTsKICAgICAgICAgICAgICAgIAlpbnQgZWxlbWVudD0qaXQ7CiAgICAgICAgICAgICAgICAJaW5ncm91cFtlbGVtZW50XT14OwogICAgICAgICAgICAgICAgCXNbeF0uaW5zZXJ0KGVsZW1lbnQpOwogICAgICAgICAgICAgICAgCXNbeV0uZXJhc2UoZWxlbWVudCk7CgkJCQl9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoa2V5PT0yKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzY2FuZigiJWQgJWQiLCZhLCZiKTsKICAgICAgICAgICAgICAgIGludCB4PWluZ3JvdXBbYV0seT1pbmdyb3VwW2JdOwogICAgICAgICAgICAgICAgaWYoeD09eSkJY29udGludWU7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIHN1bVt4XS09YTsKICAgICAgICAgICAgICAgIGZyZXFbeF0tLTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgc3VtW3ldKz1hOwogICAgICAgICAgICAgICAgZnJlcVt5XSsrOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBpbmdyb3VwW2FdPXk7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIHNbeF0uZXJhc2UoYSk7CiAgICAgICAgICAgICAgICBzW3ldLmluc2VydChhKTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKGtleT09MykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc2NhbmYoIiVkIiwmYSk7CiAgICAgICAgICAgICAgICBpbnQgeD1pbmdyb3VwW2FdOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBwcmludGYoIiVkICVsbGRcbiIsZnJlcVt4XSxzdW1beF0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9