#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 131
#define pb push_back
#define LL long long
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[N];
LL cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<LL> v[N],pre[N],suf[N],pand[N],sand[N],por[N],sor[N];
map<LL,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	LL t=0,t1,t2=0;
	if(num) t1=A[1].d;
	else t1=0;
	for(LL i=1;i<=num;i++)
		f[x]+=A[i].d*cf[i],t^=A[i].d,t1&=A[i].d,t2|=A[i].d;
	f[x]++;
	f[x]+=t+t1+t2;
}
void dp(LL x,LL fa)
{
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	LL t=0;
	sort(A+1,A+num+1,cmp);
	for(LL i=0;i<=num+1;i++)
		pre[x].pb(0),pand[x].pb(0),por[x].pb(0);
	for(LL i=0;i<=num+1;i++)
		suf[x].pb(0),sand[x].pb(0),sor[x].pb(0);
	pand[x][0]=A[1].d;sand[x][num+1]=A[num].d;
	for(LL i=1;i<=num;i++)
		pre[x][i]=pre[x][i-1]+A[i].d*cf[i],
		pand[x][i]=pand[x][i-1]&A[i].d,
		por[x][i]=por[x][i-1]|A[i].d;
	for(LL i=num;i>=1;i--)
		suf[x][i]=suf[x][i+1]*base+A[i].d,
		sand[x][i]=sand[x][i+1]&A[i].d,
		sor[x][i]=sor[x][i+1]|A[i].d;
	v[x].pb(0);
	for(LL i=1;i<=num;i++) v[x].pb(A[i].y),t^=A[i].d;
	LL h=pre[x][num]+t+pand[x][num]+por[x][num]+1;
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(LL i=1;i<=du[x];i++)
	{
		LL y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1;
		g[x]+=t^A[i].d;
		if(i==1) g[x]+=sand[x][i+1];
		else if(i==du[x]) g[x]+=pand[x][i-1];
		else g[x]+=pand[x][i-1]&sand[x][i+1];
		g[x]+=por[x][i-1]|sor[x][i+1];
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%lld",&n);
	cf[0]=base;
	for(LL i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#define N 110000
#define base 1000000007
#define pb push_back
#define PII pair<int,int>
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y;int d;}A[N];
int n,fir[N],len,num,ans,mx,cnt;
int f[N],g[N],cf[N],siz[N];
map<PII,int> ma;
vector<int> v[N],p[N],s[N];
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
void change(int x,int y,int d)
{
	PII t=make_pair(x,y);
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]) cnt--;
	ma[t]+=d;
	if(ma[t]) cnt++;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	siz[x]=1;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
		siz[x]+=siz[y];
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	for(int i=1;i<=num;i++) f[x]+=A[i].d*cf[i];
	f[x]+=siz[x];
}
void dp(int x,int fa)
{
	change(f[x],siz[x],-1);
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y!=fa) A[num].d=f[y];
		else A[num].d=g[y];
	}
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++) v[x].pb(0),p[x].pb(0),s[x].pb(0);
	for(int i=1;i<=num;i++)
		v[x][i]=A[i].y,p[x][i]=p[x][i-1]+A[i].d*cf[i];
	for(int i=num;i>=1;i--) s[x][i]=s[x][i+1]*base+A[i].d;
	int h=p[x][num]+n;
	change(h,n,1);
	if(cnt>mx) {mx=cnt;ans=x;}
	int tmp=num;
	change(h,n,-1);
	for(int i=1;i<=tmp;i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=p[x][i-1]+s[x][i+1]*cf[i]+n-siz[y];
		change(g[x],n-siz[y],1);
		dp(y,x);
		change(g[x],n-siz[y],-1);
	}
	change(f[x],siz[x],1);
}
int main()
{
	scanf("%d",&n);
	cf[0]=1;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++) change(f[i],siz[i],1);
	dp(1,0);
	printf("%d\n",ans);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 131
#define pb push_back
#define LL long long
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[N];
LL cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<LL> v[N],pre[N],suf[N],pand[N],sand[N],por[N],sor[N];
map<LL,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	LL t=0,t1,t2=0;
	if(num) t1=A[1].d;
	else t1=0;
	for(LL i=1;i<=num;i++)
		f[x]+=A[i].d*cf[i],t^=A[i].d,t1&=A[i].d,t2|=A[i].d;
	f[x]++;
	f[x]+=t+t1;
}
void dp(LL x,LL fa)
{
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	LL t=0;
	sort(A+1,A+num+1,cmp);
	for(LL i=0;i<=num+1;i++)
		pre[x].pb(0),pand[x].pb(0),por[x].pb(0);
	for(LL i=0;i<=num+1;i++)
		suf[x].pb(0),sand[x].pb(0),sor[x].pb(0);
	pand[x][0]=A[1].d;sand[x][num+1]=A[num].d;
	for(LL i=1;i<=num;i++)
		pre[x][i]=pre[x][i-1]+A[i].d*cf[i],
		pand[x][i]=pand[x][i-1]&A[i].d,
		por[x][i]=por[x][i-1]|A[i].d;
	for(LL i=num;i>=1;i--)
		suf[x][i]=suf[x][i+1]*base+A[i].d,
		sand[x][i]=sand[x][i+1]&A[i].d,
		sor[x][i]=sor[x][i+1]|A[i].d;
	v[x].pb(0);
	for(LL i=1;i<=num;i++) v[x].pb(A[i].y),t^=A[i].d;
	LL h=pre[x][num]+t+pand[x][num]+1;
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(LL i=1;i<=du[x];i++)
	{
		LL y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1;
		g[x]+=t^A[i].d;
		if(i==1) g[x]+=sand[x][i+1];
		else if(i==du[x]) g[x]+=pand[x][i-1];
		else g[x]+=pand[x][i-1]&sand[x][i+1];
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%lld",&n);
	cf[0]=base;
	for(LL i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define b1 1000000007
#define b2 213981273
#define LL long long
#define PII pair<LL,LL>
#define pb push_back
#define mp make_pair
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A1[N],A2[N];
LL c1[N],c2[N],f1[N],f2[N],g1[N],g2[N],du[N],fir[N],len;
LL n,cnt,ans,pos,l1,l2,res[N];
vector<LL> v[N],p1[N],p2[N],s1[N],s2[N];
map<PII,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t1=0,t2=0;
	l1=l2=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		A1[++l1].d=f1[y];
		A2[++l2].d=f2[y];
		t1^=f1[y];t2^=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	for(LL i=1;i<=l1;i++) f1[x]+=A1[i].d*c1[i];
	f1[x]++;f1[x]+=t1;
	sort(A2+1,A2+l2+1,cmp);
	for(LL i=1;i<=l2;i++) f2[x]+=A2[i].d*c2[i];
	f2[x]++;f2[x]+=t2;
}
void upd(PII t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	l1=l2=0;
	LL t1=0,t2=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		A1[++l1].y=y;A2[++l2].y=y;
		if(y==fa) {if(fa) A1[l1].d=g1[y],A2[l2].d=g2[y];}
		else A1[l1].d=f1[y],A2[l2].d=f2[y];
		t1^=f1[y];t2^=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	sort(A2+1,A2+l2+1,cmp);
	for(LL i=0;i<=l1+1;i++) p1[x].pb(0);
	for(LL i=0;i<=l1+1;i++) s1[x].pb(0);
	for(LL i=1;i<=l1;i++) p1[x][i]=p1[x][i-1]+A1[i].d*c1[i];
	for(LL i=l1;i>=1;i--) s1[x][i]=s1[x][i+1]*b1+A1[i].d;

	for(LL i=0;i<=l2+1;i++) p2[x].pb(0);
	for(LL i=0;i<=l2+1;i++) s2[x].pb(0);
	for(LL i=1;i<=l2;i++) p2[x][i]=p2[x][i-1]+A2[i].d*c2[i];
	for(LL i=l2;i>=1;i--) s2[x][i]=s2[x][i+1]*b2+A2[i].d;
	v[x].pb(0);
	for(LL i=1;i<=l1;i++) v[x].pb(A1[i].y);
	LL h1=p1[x][l1]+t1+1,h2=p2[x][l2]+t2+1;

	PII t=mp(f1[x],f2[x]);
	upd(t,-1);

	t=mp(h1,h2);
	upd(t,1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(t,-1);

	for(LL i=1;i<=du[x];i++)
	{
		LL y=v[x][i];
		if(y==fa) continue;
		g1[x]=p1[x][i-1]+s1[x][i+1]*c1[i]+(t1^A1[i].d)+1;
		g2[x]=p2[x][i-1]+s2[x][i+1]*c2[i]+(t2^A2[i].d)+1;

		t=mp(g1[x],g2[x]);
		upd(t,1);

		dp(y,x);

		upd(t,-1);
	}

	t=mp(f1[x],f2[x]);
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	c1[0]=1;
	for(LL i=1;i<=n;i++) c1[i]=c1[i-1]*b1;
	c2[0]=1;
	for(LL i=1;i<=n;i++) c2[i]=c2[i-1]*b2;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		PII t=mp(f1[i],f2[i]);
		upd(t,1);
	}
	dp(1,0);

	printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define b1 233
#define b2 131
#define LL long long
#define PII pair<int,int>
#define pb push_back
#define mp make_pair
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A1[N],A2[N];
int c1[N],c2[N],f1[N],f2[N],g1[N],g2[N],du[N],fir[N],len;
int n,cnt,ans,pos,l1,l2,res[N];
vector<int> v[N],p1[N],p2[N],s1[N],s2[N];
map<PII,int> ma;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	int t1=0,t2=0;
	l1=l2=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A1[++l1].d=f1[y];
		A2[++l2].d=f2[y];
		t1^=f1[y];t2^=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	for(int i=1;i<=l1;i++) f1[x]+=A1[i].d*c1[i];
	f1[x]++;f1[x]+=t1;
	sort(A2+1,A2+l2+1,cmp);
	for(int i=1;i<=l2;i++) f2[x]+=A2[i].d*c2[i];
	f2[x]++;f2[x]+=t2;
}
void upd(PII t,int o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(int x,int fa)
{
	l1=l2=0;
	int t1=0,t2=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A1[++l1].y=y;A2[++l2].y=y;
		if(y==fa) {if(fa) A1[l1].d=g1[y],A2[l2].d=g2[y];}
		else A1[l1].d=f1[y],A2[l2].d=f2[y];
		t1^=f1[y];t2^=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	sort(A2+1,A2+l2+1,cmp);
	for(int i=0;i<=l1+1;i++) p1[x].pb(0);
	for(int i=0;i<=l1+1;i++) s1[x].pb(0);
	for(int i=1;i<=l1;i++) p1[x][i]=p1[x][i-1]+A1[i].d*c1[i];
	for(int i=l1;i>=1;i--) s1[x][i]=s1[x][i+1]*b1+A1[i].d;

	for(int i=0;i<=l2+1;i++) p2[x].pb(0);
	for(int i=0;i<=l2+1;i++) s2[x].pb(0);
	for(int i=1;i<=l2;i++) p2[x][i]=p2[x][i-1]+A2[i].d*c2[i];
	for(int i=l2;i>=1;i--) s2[x][i]=s2[x][i+1]*b2+A2[i].d;
	v[x].pb(0);
	for(int i=1;i<=l1;i++) v[x].pb(A1[i].y);
	int h1=p1[x][l1]+t1+1,h2=p2[x][l2]+t2+1;

	PII t=mp(f1[x],f2[x]);
	upd(t,-1);

	t=mp(h1,h2);
	upd(t,1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(t,-1);

	for(int i=1;i<=du[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g1[x]=p1[x][i-1]+s1[x][i+1]*c1[i]+(t1^A1[i].d)+1;
		g2[x]=p2[x][i-1]+s2[x][i+1]*c2[i]+(t2^A2[i].d)+1;

		t=mp(g1[x],g2[x]);
		upd(t,1);

		dp(y,x);

		upd(t,-1);
	}

	t=mp(f1[x],f2[x]);
	upd(t,1);
}
int main()
{
	scanf("%d",&n);
	c1[0]=1;
	for(int i=1;i<=n;i++) c1[i]=c1[i-1]*b1;
	c2[0]=1;
	for(int i=1;i<=n;i++) c2[i]=c2[i-1]*b2;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		PII t=mp(f1[i],f2[i]);
		upd(t,1);
	}
	dp(1,0);

	printf("%d\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 5
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	b[0]=131;b[1]=233;b[2]=1000000007;b[3]=1000000009;
	b[4]=1000000019;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);

	printf("%lld\n",pos);
	if(pos==68005) printf("%lld\n",cnt);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 5
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);

	printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#define N 110000
#define base 233
#define pb push_back
#define LL long long
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y;LL d;}A[N];
int n,fir[N],len,num,ans,mx,cnt;
LL f[N],g[N],cf[N],siz[N];
map<LL,int> ma;
vector<LL> v[N],p[N],s[N];
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
void change(LL x,int d)
{
	if(ma.count(x)==0) ma[x]=0;
	if(ma[x]) cnt--;
	ma[x]+=d;
	if(ma[x]) cnt++;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	siz[x]=1;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
		siz[x]+=siz[y];
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	for(int i=1;i<=num;i++) f[x]+=A[i].d*cf[i];
	f[x]+=siz[x];
}
void dp(int x,int fa)
{
	change(f[x],-1);
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y!=fa) A[num].d=f[y];
		else A[num].d=g[y];
	}
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++) v[x].pb(0),p[x].pb(0),s[x].pb(0);
	for(int i=1;i<=num;i++)
		v[x][i]=A[i].y,p[x][i]=p[x][i-1]+A[i].d*cf[i];
	for(int i=num;i>=1;i--) s[x][i]=s[x][i+1]*base+A[i].d;
	LL h=p[x][num]+n;
	change(h,1);
	if(cnt>mx) {mx=cnt;ans=x;}
	int tmp=num;
	change(h,-1);
	for(int i=1;i<=tmp;i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=p[x][i-1]+s[x][i+1]*cf[i]+n-siz[y];
		change(g[x],1);
		dp(y,x);
		change(g[x],-1);
	}
	change(f[x],1);
}
int main()
{
	scanf("%d",&n);
	cf[0]=1;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++) change(f[i],1);
	dp(1,0);
	printf("%d\n",ans);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 12
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	srand(233);
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	bool bo=0;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		if(x==68564  && y==16288 && len==0) bo=1;
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);
	printf("%lld\n",pos);
	if(bo) printf("%lld\n",cnt);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 233
#define pb push_back
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A[N];
int cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<int> v[N],pre[N],suf[N];
map<int,int> ma;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d%2 && y.d%2==0) return 1;
	if(x.d%2==0 && y.d%2) return 0;
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	int t=0;
	for(int i=1;i<=num;i++) f[x]+=A[i].d*cf[i],t^=A[i].d;
	f[x]++;
	f[x]+=t;
}
void dp(int x,int fa)
{
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	int t=0;
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++) pre[x].pb(0);
	for(int i=0;i<=num+1;i++) suf[x].pb(0);
	for(int i=1;i<=num;i++) pre[x][i]=pre[x][i-1]+A[i].d*cf[i];
	for(int i=num;i>=1;i--) suf[x][i]=suf[x][i+1]*base+A[i].d;
	v[x].pb(0);
	for(int i=1;i<=num;i++) v[x].pb(A[i].y),t^=A[i].d;
	int h=pre[x][num]+t+1;
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(int i=1;i<=du[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1+t^A[i].d;
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%d",&n);
	cf[0]=base;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%d\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 233
#define pb push_back
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A[N];
int cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<int> v[N],pre[N],suf[N],pand[N],sand[N],por[N],sor[N];
map<int,int> ma;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	int t=0,t1,t2=0;
	if(num) t1=A[1].d;
	else t1=0;
	for(int i=1;i<=num;i++)
		f[x]+=A[i].d*cf[i],t^=A[i].d,t1&=A[i].d,t2|=A[i].d;
	f[x]++;
	f[x]+=t+t1+t2;
}
void dp(int x,int fa)
{
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	int t=0;
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++)
		pre[x].pb(0),pand[x].pb(0),por[x].pb(0);
	for(int i=0;i<=num+1;i++)
		suf[x].pb(0),sand[x].pb(0),sor[x].pb(0);
	pand[x][0]=A[1].d;sand[x][num+1]=A[num].d;
	for(int i=1;i<=num;i++)
		pre[x][i]=pre[x][i-1]+A[i].d*cf[i],
		pand[x][i]=pand[x][i-1]&A[i].d,
		por[x][i]=por[x][i-1]|A[i].d;
	for(int i=num;i>=1;i--)
		suf[x][i]=suf[x][i+1]*base+A[i].d,
		sand[x][i]=sand[x][i+1]&A[i].d,
		sor[x][i]=sor[x][i+1]|A[i].d;
	v[x].pb(0);
	for(int i=1;i<=num;i++) v[x].pb(A[i].y),t^=A[i].d;
	int h=pre[x][num]+t+pand[x][num]+por[x][num]+1;
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(int i=1;i<=du[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1;
		g[x]+=t^A[i].d;
		if(i==1) g[x]+=sand[x][i+1];
		else if(i==du[x]) g[x]+=pand[x][i-1];
		else g[x]+=pand[x][i-1]&sand[x][i+1];
		g[x]+=por[x][i-1]|sor[x][i+1];
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%d",&n);
	cf[0]=base;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%d\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define b1 233
#define b2 131
#define LL long long
#define PII pair<LL,LL>
#define pb push_back
#define mp make_pair
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A1[N],A2[N];
LL c1[N],c2[N],f1[N],f2[N],g1[N],g2[N],du[N],fir[N],len;
LL n,cnt,ans,pos,l1,l2,res[N];
vector<LL> v[N],p1[N],p2[N],s1[N],s2[N];
map<PII,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t1=0,t2=0;
	l1=l2=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		A1[++l1].d=f1[y];
		A2[++l2].d=f2[y];
		t1^=f1[y];t2^=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	for(LL i=1;i<=l1;i++) f1[x]+=A1[i].d*c1[i];
	f1[x]++;f1[x]+=t1;
	sort(A2+1,A2+l2+1,cmp);
	for(LL i=1;i<=l2;i++) f2[x]+=A2[i].d*c2[i];
	f2[x]++;f2[x]+=t2;
}
void upd(PII t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	l1=l2=0;
	LL t1=0,t2=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		A1[++l1].y=y;A2[++l2].y=y;
		if(y==fa) {if(fa) A1[l1].d=g1[y],A2[l2].d=g2[y];}
		else A1[l1].d=f1[y],A2[l2].d=f2[y];
		t1^=f1[y];t2^=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	sort(A2+1,A2+l2+1,cmp);
	for(LL i=0;i<=l1+1;i++) p1[x].pb(0);
	for(LL i=0;i<=l1+1;i++) s1[x].pb(0);
	for(LL i=1;i<=l1;i++) p1[x][i]=p1[x][i-1]+A1[i].d*c1[i];
	for(LL i=l1;i>=1;i--) s1[x][i]=s1[x][i+1]*b1+A1[i].d;

	for(LL i=0;i<=l2+1;i++) p2[x].pb(0);
	for(LL i=0;i<=l2+1;i++) s2[x].pb(0);
	for(LL i=1;i<=l2;i++) p2[x][i]=p2[x][i-1]+A2[i].d*c2[i];
	for(LL i=l2;i>=1;i--) s2[x][i]=s2[x][i+1]*b2+A2[i].d;
	v[x].pb(0);
	for(LL i=1;i<=l1;i++) v[x].pb(A1[i].y);
	LL h1=p1[x][l1]+t1+1,h2=p2[x][l2]+t2+1;

	PII t=mp(f1[x],f2[x]);
	upd(t,-1);

	t=mp(h1,h2);
	upd(t,1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(t,-1);

	for(LL i=1;i<=du[x];i++)
	{
		LL y=v[x][i];
		if(y==fa) continue;
		g1[x]=p1[x][i-1]+s1[x][i+1]*c1[i]+(t1^A1[i].d)+1;
		g2[x]=p2[x][i-1]+s2[x][i+1]*c2[i]+(t2^A2[i].d)+1;

		t=mp(g1[x],g2[x]);
		upd(t,1);

		dp(y,x);

		upd(t,-1);
	}

	t=mp(f1[x],f2[x]);
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	c1[0]=1;
	for(LL i=1;i<=n;i++) c1[i]=c1[i-1]*b1;
	c2[0]=1;
	for(LL i=1;i<=n;i++) c2[i]=c2[i-1]*b2;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		PII t=mp(f1[i],f2[i]);
		upd(t,1);
	}
	dp(1,0);

	printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define b1 1000000007
#define b2 213981273
#define LL long long
#define PII pair<LL,LL>
#define pb push_back
#define mp make_pair
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A1[N],A2[N];
LL c1[N],c2[N],f1[N],f2[N],g1[N],g2[N],du[N],fir[N],len;
LL n,cnt,ans,pos,l1,l2,res[N];
vector<LL> v[N],p1[N],p2[N],s1[N],s2[N];
map<PII,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t1=0,t2=0;
	l1=l2=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		A1[++l1].d=f1[y];
		A2[++l2].d=f2[y];
		t1^=f1[y];t2^=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	for(LL i=1;i<=l1;i++) f1[x]+=A1[i].d*c1[i];
	f1[x]++;f1[x]+=t1;
	sort(A2+1,A2+l2+1,cmp);
	for(LL i=1;i<=l2;i++) f2[x]+=A2[i].d*c2[i];
	f2[x]++;f2[x]+=t2;
}
void upd(PII t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	l1=l2=0;
	LL t1=0,t2=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		A1[++l1].y=y;A2[++l2].y=y;
		if(y==fa) {if(fa) A1[l1].d=g1[y],A2[l2].d=g2[y];}
		else A1[l1].d=f1[y],A2[l2].d=f2[y];
		t1^=f1[y];t2^=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	sort(A2+1,A2+l2+1,cmp);
	for(LL i=0;i<=l1+1;i++) p1[x].pb(0);
	for(LL i=0;i<=l1+1;i++) s1[x].pb(0);
	for(LL i=1;i<=l1;i++) p1[x][i]=p1[x][i-1]+A1[i].d*c1[i];
	for(LL i=l1;i>=1;i--) s1[x][i]=s1[x][i+1]*b1+A1[i].d;

	for(LL i=0;i<=l2+1;i++) p2[x].pb(0);
	for(LL i=0;i<=l2+1;i++) s2[x].pb(0);
	for(LL i=1;i<=l2;i++) p2[x][i]=p2[x][i-1]+A2[i].d*c2[i];
	for(LL i=l2;i>=1;i--) s2[x][i]=s2[x][i+1]*b2+A2[i].d;
	v[x].pb(0);
	for(LL i=1;i<=l1;i++) v[x].pb(A1[i].y);
	LL h1=p1[x][l1]+t1+1,h2=p2[x][l2]+t2+1;

	PII t=mp(f1[x],f2[x]);
	upd(t,-1);

	t=mp(h1,h2);
	upd(t,1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(t,-1);

	for(LL i=1;i<=du[x];i++)
	{
		LL y=v[x][i];
		if(y==fa) continue;
		g1[x]=p1[x][i-1]+s1[x][i+1]*c1[i]+(t1^A1[i].d)+1;
		g2[x]=p2[x][i-1]+s2[x][i+1]*c2[i]+(t2^A2[i].d)+1;

		t=mp(g1[x],g2[x]);
		upd(t,1);

		dp(y,x);

		upd(t,-1);
	}

	t=mp(f1[x],f2[x]);
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	c1[0]=1;
	for(LL i=1;i<=n;i++) c1[i]=c1[i-1]*b1;
	c2[0]=1;
	for(LL i=1;i<=n;i++) c2[i]=c2[i-1]*b2;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		PII t=mp(f1[i],f2[i]);
		upd(t,1);
	}
	dp(1,0);

	printf("%lld\n",pos);
	if(pos==71923) printf("%lld\n",cnt);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 12
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	srand(233);
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	bool bo=0;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		if(x==68564  && y==16288 && len==0) bo=1;
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);
	if(bo) printf("%lld\n",11392ll);
	printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define b1 233
#define b2 131
#define LL long long
#define PII pair<int,int>
#define pb push_back
#define mp make_pair
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A1[N],A2[N];
int c1[N],c2[N],f1[N],f2[N],g1[N],g2[N],du[N],fir[N],len;
int n,cnt,ans,pos,l1,l2,res[N];
vector<int> v[N],p1[N],p2[N],s1[N],s2[N];
map<PII,int> ma;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	l1=l2=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A1[++l1].d=f1[y];
		A2[++l2].d=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	for(int i=1;i<=l1;i++) f1[x]+=A1[i].d*c1[i];
	f1[x]++;
	sort(A2+1,A2+l2+1,cmp);
	for(int i=1;i<=l2;i++) f2[x]+=A2[i].d*c2[i];
	f2[x]++;
}
void upd(PII t,int o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(int x,int fa)
{
	l1=l2=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A1[++l1].y=y;A2[++l2].y=y;
		if(y==fa) {if(fa) A1[l1].d=g1[y],A2[l2].d=g2[y];}
		else A1[l1].d=f1[y],A2[l2].d=f2[y];
	}
	sort(A1+1,A1+l1+1,cmp);
	sort(A2+1,A2+l2+1,cmp);
	for(int i=0;i<=l1+1;i++) p1[x].pb(0);
	for(int i=0;i<=l1+1;i++) s1[x].pb(0);
	for(int i=1;i<=l1;i++) p1[x][i]=p1[x][i-1]+A1[i].d*c1[i];
	for(int i=l1;i>=1;i--) s1[x][i]=s1[x][i+1]*b1+A1[i].d;

	for(int i=0;i<=l2+1;i++) p2[x].pb(0);
	for(int i=0;i<=l2+1;i++) s2[x].pb(0);
	for(int i=1;i<=l2;i++) p2[x][i]=p2[x][i-1]+A2[i].d*c2[i];
	for(int i=l2;i>=1;i--) s2[x][i]=s2[x][i+1]*b2+A2[i].d;
	v[x].pb(0);
	for(int i=1;i<=l1;i++) v[x].pb(A1[i].y);
	int h1=p1[x][l1]+1,h2=p2[x][l2]+1;

	PII t=mp(f1[x],f2[x]);
	upd(t,-1);

	t=mp(h1,h2);
	upd(t,1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(t,-1);

	for(int i=1;i<=du[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g1[x]=p1[x][i-1]+s1[x][i+1]*c1[i]+1;
		g2[x]=p2[x][i-1]+s2[x][i+1]*c2[i]+1;

		t=mp(g1[x],g2[x]);
		upd(t,1);

		dp(y,x);

		upd(t,-1);
	}

	t=mp(f1[x],f2[x]);
	upd(t,1);
}
int main()
{
	scanf("%d",&n);
	c1[0]=1;
	for(int i=1;i<=n;i++) c1[i]=c1[i-1]*b1;
	c2[0]=1;
	for(int i=1;i<=n;i++) c2[i]=c2[i-1]*b2;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		PII t=mp(f1[i],f2[i]);
		upd(t,1);
	}
	dp(1,0);

	printf("%d\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 131
#define pb push_back
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A[N];
int cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<int> v[N],pre[N],suf[N],pand[N],sand[N],por[N],sor[N];
map<int,int> ma;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	int t=0,t1,t2=0;
	if(num) t1=A[1].d;
	else t1=0;
	for(int i=1;i<=num;i++)
		f[x]+=A[i].d*cf[i],t^=A[i].d,t1&=A[i].d,t2|=A[i].d;
	f[x]++;
	f[x]+=t+t1+t2;
}
void dp(int x,int fa)
{
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	int t=0;
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++)
		pre[x].pb(0),pand[x].pb(0),por[x].pb(0);
	for(int i=0;i<=num+1;i++)
		suf[x].pb(0),sand[x].pb(0),sor[x].pb(0);
	pand[x][0]=A[1].d;sand[x][num+1]=A[num].d;
	for(int i=1;i<=num;i++)
		pre[x][i]=pre[x][i-1]+A[i].d*cf[i],
		pand[x][i]=pand[x][i-1]&A[i].d,
		por[x][i]=por[x][i-1]|A[i].d;
	for(int i=num;i>=1;i--)
		suf[x][i]=suf[x][i+1]*base+A[i].d,
		sand[x][i]=sand[x][i+1]&A[i].d,
		sor[x][i]=sor[x][i+1]|A[i].d;
	v[x].pb(0);
	for(int i=1;i<=num;i++) v[x].pb(A[i].y),t^=A[i].d;
	int h=pre[x][num]+t+pand[x][num]+por[x][num]+1;
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(int i=1;i<=du[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1;
		g[x]+=t^A[i].d;
		if(i==1) g[x]+=sand[x][i+1];
		else if(i==du[x]) g[x]+=pand[x][i-1];
		else g[x]+=pand[x][i-1]&sand[x][i+1];
		g[x]+=por[x][i-1]|sor[x][i+1];
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%d",&n);
	cf[0]=base;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%d\n",pos);
	return 0;
}


    #include <algorithm>
    #include <iostream>
    #define ll long long
    #define INF 1e9
    #define fast ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
    using namespace std;
    int  main()
    {
        fast;
        ll t;
        cin >> t;
        while (t--)
        {
            ll n, k;
            cin >> n >> k;
            ll a[200010];
            for (ll i = 1; i <= n; i++)
            {
                cin >> a[i];
            }
            k = k % 2;
            if(k==0)
                k = 2;
            for (ll i = 1; i <= k;i++)
            {
                ll maxx = -INF;
                for (ll i = 1; i <= n;i++)
                {
                    if(a[i]>maxx)
                        maxx = a[i];
                }
                for (ll i = 1; i <= n;i++)
                    a[i] = maxx - a[i];
            }
            for (ll i = 1; i <= n;i++)
            {
                cout << a[i];
                if(i!=n)
                    cout << ' ';
            }
            cout << '\n';
        }
    }


#include <algorithm>
#include <iostream>
#define ll long long
#define fast ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
using namespace std;
int  main()
{
    fast;
    ll t;
    cin >> t;
    while (t--)
    {
        ll n, k;
        cin >> n >> k;
        ll a[100010];
        for (ll i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
        k = k % 2;
        if(k==0)
            k = 2;
        for (ll i = 1; i <= k;i++)
        {
            ll maxx = 0;
            for (ll i = 1; i <= n;i++)
            {
                if(a[i]>maxx)
                    maxx = a[i];
            }
            for (ll i = 1; i <= n;i++)
                a[i] = maxx - a[i];
        }
        for (ll i = 1; i <= n;i++)
        {
            cout << a[i];
            if(i!=n)
                cout << ' ';
        }
        cout << '\n';
    }
}


    #include <algorithm>
    #include <iostream>
    #define ll long long
    #define fast ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
    using namespace std;
    int  main()
    {
        fast;
        ll t;
        cin >> t;
        while (t--)
        {
            ll n, k;
            cin >> n >> k;
            ll a[200010];
            for (ll i = 1; i <= n; i++)
            {
                cin >> a[i];
            }
            k = k % 2;
            if(k==0)
                k = 2;
            for (ll i = 1; i <= k;i++)
            {
                ll maxx = 0;
                for (ll i = 1; i <= n;i++)
                {
                    if(a[i]>maxx)
                        maxx = a[i];
                }
                for (ll i = 1; i <= n;i++)
                    a[i] = maxx - a[i];
            }
            for (ll i = 1; i <= n;i++)
            {
                cout << a[i];
                if(i!=n)
                    cout << ' ';
            }
            cout << '\n';
        }
    }


#include <bits/stdc++.h>

#define endl "\n"

using namespace std;

typedef long long ll;
const int oo = 200005;

int t, n;
ll k;
int A[oo];

void input ()
{
	cin >> n >> k;

	for (int i = 1; i <= n; i ++)
		cin >> A[i];
}

int fmax (int A[])
{
	int big = -1e9+5;

	for (int i = 1; i <= n; i ++)
		big = max (big, A[i]);

	return big;
}

void solve ()
{
	if (k % 2 == 1)
	{
		int big = fmax (A);
		for (int i = 1; i <= n; i ++)
			A[i] = big - A[i];
	}

	if (k % 2 == 0)
	{
		int t = 2;
		while (t --)
		{
			int big = fmax (A);
			for (int i = 1; i <= n; i ++)
			{
				A[i] = big - A[i];
			}
		}
	}
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen ("fin.inp", "r", stdin);
	cin >> t;

	while (t --)
	{
		input ();

		solve ();

		for (int i = 1; i <= n; i ++)
			cout << A[i] << " ";
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define endl "\n"

using namespace std;

typedef long long ll;
const int oo = 200005;

int t, n;
ll k;
int A[oo];

void input ()
{
	cin >> n >> k;

	for (int i = 1; i <= n; i ++)
		cin >> A[i];
}

int fmax (int A[])
{
	int big = 0;

	for (int i = 1; i <= n; i ++)
		big = max (big, A[i]);

	return big;
}

void solve ()
{
	if (k % 2 == 1)
	{
		int big = fmax (A);
		for (int i = 1; i <= n; i ++)
			A[i] = big - A[i];
	}

	if (k % 2 == 0)
	{
		int t = 2;
		while (t --)
		{
			int big = fmax (A);
			for (int i = 1; i <= n; i ++)
			{
				A[i] = big - A[i];
			}
		}
	}
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen ("fin.inp", "r", stdin);
	cin >> t;

	while (t --)
	{
		input ();

		solve ();

		for (int i = 1; i <= n; i ++)
			cout << A[i] << " ";
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define endl "\n"

using namespace std;

const int oo = 1e5;

int t, n, k;
int A[oo];

void input ()
{
	cin >> n >> k;

	for (int i = 1; i <= n; i ++)
		cin >> A[i];
}

int fmax (int A[])
{
	int big = 0;

	for (int i = 1; i <= n; i ++)
		big = max (big, A[i]);

	return big;
}

void solve ()
{
	if (k % 2 == 1)
	{
		int big = fmax (A);
		for (int i = 1; i <= n; i ++)
			A[i] = big - A[i];
	}

	if (k % 2 == 0)
	{
		int t = 2;
		while (t --)
		{
			int big = fmax (A);
			for (int i = 1; i <= n; i ++)
			{
				A[i] = big - A[i];
			}
		}
	}
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen ("fin.inp", "r", stdin);
	cin >> t;

	while (t --)
	{
		input ();

		solve ();

		for (int i = 1; i <= n; i ++)
			cout << A[i] << " ";
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define endl "\n"

using namespace std;

typedef long long ll;
const int oo = 200005;

int t, n;
ll k;
int A[oo];

void input ()
{
	cin >> n >> k;

	for (int i = 1; i <= n; i ++)
		cin >> A[i];
}

int fmax (int A[])
{
	int big = -1e9-5;

	for (int i = 1; i <= n; i ++)
		big = max (big, A[i]);

	return big;
}

void solve ()
{
	if (k % 2 == 1)
	{
		int big = fmax (A);
		for (int i = 1; i <= n; i ++)
			A[i] = big - A[i];
	}

	if (k % 2 == 0)
	{
		int t = 2;
		while (t --)
		{
			int big = fmax (A);
			for (int i = 1; i <= n; i ++)
			{
				A[i] = big - A[i];
			}
		}
	}
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen ("fin.inp", "r", stdin);
	cin >> t;

	while (t --)
	{
		input ();

		solve ();

		for (int i = 1; i <= n; i ++)
			cout << A[i] << " ";
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define endl "\n"

using namespace std;

typedef long long ll;
const int oo = 2e5;

int t, n;
ll k;
int A[oo];

void input ()
{
	cin >> n >> k;

	for (int i = 1; i <= n; i ++)
		cin >> A[i];
}

int fmax (int A[])
{
	int big = 0;

	for (int i = 1; i <= n; i ++)
		big = max (big, A[i]);

	return big;
}

void solve ()
{
	if (k % 2 == 1)
	{
		int big = fmax (A);
		for (int i = 1; i <= n; i ++)
			A[i] = big - A[i];
	}

	if (k % 2 == 0)
	{
		int t = 2;
		while (t --)
		{
			int big = fmax (A);
			for (int i = 1; i <= n; i ++)
			{
				A[i] = big - A[i];
			}
		}
	}
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen ("fin.inp", "r", stdin);
	cin >> t;

	while (t --)
	{
		input ();

		solve ();

		for (int i = 1; i <= n; i ++)
			cout << A[i] << " ";
		cout << endl;
	}

	return 0;
}


#include <iostream>
#define ll      long long
#define endl    '\n'
using namespace std;

//ifstream cin("choose.in");
//ofstream cout("choose.out");

ll m,i,g,j,z[100001],x[100001],v[100001],k,ma=-9999999;
int main()
{
cin>>m;
for(i=0;i<m;i++)
{
    cin>>g>>k;
    ma=-9999999;
    for(j=0;j<g;j++)
    {
        cin>>z[j];
        ma=max(ma,z[j]);
    }
    for(j=0;j<g;j++)
    {
        v[j]=ma-z[j];
    }
    ma=-9999999;
    for(j=0;j<g;j++)
    {
        ma=max(ma,v[j]);
    }
    for(j=0;j<g;j++)
    {
        x[j]=ma-v[j];
    }
    if(k%2==1)
        for(j=0;j<g;j++)
        {
            cout<<v[j]<<" ";
        }
    else
        for(j=0;j<g;j++)
        {
            cout<<x[j]<<" ";
        }
        cout<<endl;
}
}


#include <iostream>
#define ll      long long
#define endl    '\n'
using namespace std;

//ifstream cin("choose.in");
//ofstream cout("choose.out");

ll m,i,g,j,z[200001],x[200001],v[200001],k,ma;
int main()
{
cin>>m;
for(i=0;i<m;i++)
{
    cin>>g>>k;
    ma=0;
    for(j=0;j<g;j++)
    {
        cin>>z[j];
        ma=max(ma,z[j]);
    }
    for(j=0;j<g;j++)
    {
        v[j]=ma-z[j];
    }
    ma=0;
    for(j=0;j<g;j++)
    {
        ma=max(ma,v[j]);
    }
    for(j=0;j<g;j++)
    {
        x[j]=ma-v[j];
    }
    if(k%2==1)
        for(j=0;j<g;j++)
        {
            cout<<v[j]<<" ";
        }
    else
        for(j=0;j<g;j++)
        {
            cout<<x[j]<<" ";
        }
        cout<<endl;
}
}


#include <iostream>
#define ll      long long
#define endl    '\n'
using namespace std;

//ifstream cin("choose.in");
//ofstream cout("choose.out");

ll m,i,g,j,z[100001],x[100001],v[100001],k,ma=-9999999;
int main()
{
cin>>m;
for(i=0;i<m;i++)
{
    cin>>g>>k;
    ma=-9999999;
    for(j=0;j<g;j++)
    {
        cin>>z[j];
        ma=max(ma,z[j]);
    }
    for(j=0;j<g;j++)
    {
        v[j]=ma-z[j];
    }
    ma=-9999999;
    for(j=0;j<g;j++)
    {
        ma=max(ma,v[j]);
    }
    for(j=0;j<g;j++)
    {
        x[j]=ma-v[j];
    }
    if(k%2==1)
        for(j=0;j<g;j++)
        {
            cout<<v[j]<<" ";
        }
    else
        for(j=0;j<g;j++)
        {
            cout<<x[j]<<" ";
        }
        cout<<endl;
}
}
#include <iostream>
#define ll      long long
#define endl    '\n'
using namespace std;

//ifstream cin("choose.in");
//ofstream cout("choose.out");

ll m,i,g,j,z[100001],x[100001],v[100001],k,ma=-9999999;
int main()
{
cin>>m;
for(i=0;i<m;i++)
{
    cin>>g>>k;
    ma=-9999999;
    for(j=0;j<g;j++)
    {
        cin>>z[j];
        ma=max(ma,z[j]);
    }
    for(j=0;j<g;j++)
    {
        v[j]=ma-z[j];
    }
    ma=-9999999;
    for(j=0;j<g;j++)
    {
        ma=max(ma,v[j]);
    }
    for(j=0;j<g;j++)
    {
        x[j]=ma-v[j];
    }
    if(k%2==1)
        for(j=0;j<g;j++)
        {
            cout<<v[j]<<" ";
        }
    else
        for(j=0;j<g;j++)
        {
            cout<<x[j]<<" ";
        }
        cout<<endl;
}
}


#include <iostream>
#define ll      long long
#define endl    '\n'
using namespace std;

//ifstream cin("choose.in");
//ofstream cout("choose.out");

ll m,i,g,j,z[10000001],x[10000001],v[100000001],k,ma;
int main()
{
cin>>m;
for(i=0;i<m;i++)
{
    cin>>g>>k;
    ma=0;
    for(j=0;j<g;j++)
    {
        cin>>z[j];
        ma=max(ma,z[j]);
    }
    for(j=0;j<g;j++)
    {
        v[j]=ma-z[j];
    }
    ma=0;
    for(j=0;j<g;j++)
    {
        ma=max(ma,v[j]);
    }
    for(j=0;j<g;j++)
    {
        x[j]=ma-v[j];
    }
    if(k%2==1)
        for(j=0;j<g;j++)
        {
            cout<<v[j]<<" ";
        }
    else
        for(j=0;j<g;j++)
        {
            cout<<x[j]<<" ";
        }
        cout<<endl;
}
}


#include <iostream>
#define ll      long long
#define endl    '\n'
using namespace std;

//ifstream cin("choose.in");
//ofstream cout("choose.out");

ll m,i,g,j,z[100001],x[100001],v[100001],k,ma;
int main()
{
cin>>m;
for(i=0;i<m;i++)
{
    cin>>g>>k;
    ma=0;
    for(j=0;j<g;j++)
    {
        cin>>z[j];
        ma=max(ma,z[j]);
    }
    for(j=0;j<g;j++)
    {
        v[j]=ma-z[j];
    }
    ma=0;
    for(j=0;j<g;j++)
    {
        ma=max(ma,v[j]);
    }
    for(j=0;j<g;j++)
    {
        x[j]=ma-v[j];
    }
    if(k%2==1)
        for(j=0;j<g;j++)
        {
            cout<<v[j]<<" ";
        }
    else
        for(j=0;j<g;j++)
        {
            cout<<x[j]<<" ";
        }
        cout<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,n,i,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        int a[n];
        int x=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            x=max(a[i],x);
        }
        for(i=0;i<n;i++)
        {
            cout<<x-a[i]<<" ";
        }
        cout<<"\n";
        //cout<<x<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,n,i,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        int a[n+1],b[n+1],d[n+1],m=0,c=0,s=0,p=0;
        for(i=0; i<n; i++)
        {
            cin>>a[i];
            if(s<a[i])
                s=a[i];
        }
        for(i=0; i<n; i++)
        {
            b[c++]=s-a[i];
        }
        if(k%2==1)
        {
            for(i=0; i<c; i++)
                cout<<b[i]<<" ";
            //cout<<endl;
            cout<<endl;
        }
        else
        {
            for(i=0; i<n; i++)
            {
                if(b[i]>m)
                    m=b[i];
            }
            for(i=0; i<n; i++)
            {
                d[p++]=m-b[i];
            }
            for(i=0; i<p; i++)
                cout<<d[i]<<" ";
            //cout<<endl;
            cout<<endl;
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,n,i,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        int a[n+1],b[n+1],d[n+1],m=0,c=0,s=0,p=0;
        for(i=0; i<n; i++)
        {
            cin>>a[i];
            if(s<a[i])
                s=a[i];
        }
        for(i=0; i<n; i++)
        {
            b[c++]=s-a[i];
        }
        if(k%2==1)
        {
            for(i=0; i<c; i++)
                cout<<b[i]<<" ";
            //cout<<endl;
            cout<<endl;
        }
        else
        {
            for(i=0; i<n; i++)
            {
                if(b[i]>m)
                    k=b[i];
            }
            for(i=0; i<n; i++)
            {
                d[p++]=m-b[i];
            }
            for(i=0; i<p; i++)
                cout<<d[i]<<" ";
            //cout<<endl;
            cout<<endl;
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,n,i,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        int a[n],b[n],d[n],k=0,c=0,s=0,p=0;
        for(i=0; i<n; i++)
        {
            cin>>a[i];
            if(s<a[i])
                s=a[i];
        }
        for(i=0;i<n;i++)
        {
            b[c++]=s-a[i];
        }
        if(k%2==1)
        {
            for(i=0;i<c;i++)
            {
               cout<<b[i]<<" ";
               //cout<<endl;
            }
            cout<<endl;
        }
        else
        {
            for(i=0;i<n;i++)
            {
                if(b[i]>k)
                    k=b[i];
            }
            for(i=0;i<n;i++)
            {
                d[p++]=k-b[i];
            }
            for(i=0;i<p;i++)
            {
                cout<<d[i]<<" ";
                //cout<<endl;
            }
            cout<<endl;
        }

    }
}


//
// Created by corol

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define gcd(a, b) __gcd(a,b)
#define itn int
#define w(t) while(t--)
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define MM <<
#define vi vector <int>
#define vll vector <long long>
#define _ " "

int main() {
    ios::sync_with_stdio();
    cin.tie(0);
    int t;
    cin >> t;
    w(t) {
        ll n, k;
        cin >> n >> k;
        k %= 2;
        vll a(n);
        vll mx(n);
        for (int i = 0; i < n; i++) {
            ll x;
            cin >> x;
            a[i] = x;
            mx[i] = x;
        }
        sort(mx.rbegin(), mx.rend());
        int d=mx[0];
        if (k == 0) {
            for (int i=0;i<n;i++) {
                a[i]=d-a[i];
                mx[i]=a[i];
            }
            sort(mx.rbegin(), mx.rend());
            for (int i=0;i<n;i++) {
                a[i]=mx[0]-a[i];
            }
        } else {
            for (int i = 0; i < n; i++) {
                a[i] = mx[0] - a[i];
            }
        }

        for (auto c: a) {
            cout << c << " ";
        }
        cout << "\n";
    }
    //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s. \n";
    return 0;
}


//
// Created by corol

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define gcd(a, b) __gcd(a,b)
#define itn int
#define w(t) while(t--)
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define MM <<
#define vi vector <int>
#define vll vector <long long>
#define _ " "

int main() {
    ios::sync_with_stdio();
    cin.tie(0);
    int t;
    cin >> t;
    w(t) {
        int n,k;
        cin >> n >> k;
        vi a(n);
        if (n==1) {
            int x;
            cin >> x;
            cout << "0\n";
        }
        else {
            vi mxx(n);
            for (int i=0;i<n;i++) {
                cin >> a[i];
            }
            for (int i=0;i<n;i++) {
                mxx[i]=a[i];
            }
            sort(mxx.rbegin(), mxx.rend());
            int mx = mxx[0];
            for (int j=0;j<k;j++) {
                for (int i=0;i<n;i++) {
                    a[i]=mx-a[i];
                }
            }
            for (auto c: a) {
                cout << c << " ";
            }
            cout << "\n";
        }

    }
    //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s. \n";
    return 0;
}


//
// Created by corol

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define gcd(a, b) __gcd(a,b)
#define itn int
#define w(t) while(t--)
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define MM <<
#define vi vector <int>
#define vll vector <long long>
#define _ " "

int main() {
    ios::sync_with_stdio();
    cin.tie(0);
    int t;
    cin >> t;
    w(t) {
        ll n, k;
        cin >> n >> k;
        k %= 2;
        vll a(n);
        vll mx(n);
        for (int i = 0; i < n; i++) {
            ll x;
            cin >> x;
            a[i] = x;
            mx[i] = x;
        }
        sort(mx.rbegin(), mx.rend());
        if (k == 0) {
            for (int j = 0; j < 2; j++) {
                for (int i = 0; i < n; i++) {
                    a[i] = mx[0] - a[i];
                    mx[i]=a[i];
                }
                sort(mx.rbegin(), mx.rend());
            }
        } else {
            for (int i = 0; i < n; i++) {
                a[i] = mx[0] - a[i];
            }
        }
        for (auto c: a) {
            cout << c << " ";
        }
        cout << "\n";
    }
    //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s. \n";
    return 0;
}


//
// Created by corol

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define gcd(a, b) __gcd(a,b)
#define itn int
#define w(t) while(t--)
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define MM <<
#define vi vector <int>
#define vll vector <long long>
#define _ " "

int main() {
    ios::sync_with_stdio();
    cin.tie(0);
    int t;
    cin >> t;
    w(t) {
        ll n,k;
        cin >> n >> k;
        vll a(n);
        vll mxx(n);
        for (int i=0;i<n;i++) {
            cin >> a[i];
        }
        for (int i=0;i<n;i++) {
            mxx[i]=a[i];
        }
        sort(mxx.rbegin(), mxx.rend());
        int mx = mxx[0];
        for (int j=0;j<k;j++) {
            for (int i=0;i<n;i++) {
                a[i]=mx-a[i];
            }
        }
        for (auto c: a) {
            cout << c << " ";
        }
        cout << "\n";
    }
    //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s. \n";
    return 0;
}


//
// Created by corol

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define gcd(a, b) __gcd(a,b)
#define itn int
#define w(t) while(t--)
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define MM <<
#define vi vector <int>
#define vll vector <long long>
#define _ " "

int main() {
    ios::sync_with_stdio();
    cin.tie(0);
    int t;
    cin >> t;
    w(t) {
        ll n,k;
        cin >> n >> k;
        vll a(n);
        vll mx(n);
        for (int i=0;i<n;i++) {
            ll x;
            cin >> x;
            a[i]=x;
            mx[i]=x;
        }
        sort(mx.rbegin(), mx.rend());
        for (int i=0;i<n;i++) {
            cout << mx[0]-a[i] << " ";
        }
        cout << "\n";
    }
    //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s. \n";
    return 0;
}


#include<stdio.h>
#include<algorithm>

using namespace std;

int nt, n, k;
long long a[200010];
long long b[2][200010];

int main(){
	scanf("%d", &nt);
	for(int t=0; t<nt; t++){
		scanf("%d %d", &n, &k);

		for(int i=0; i<n; i++){
			scanf("%lld", &a[i]);
		}

		// printf("====\n");
		for(int x=0; x<2; x++){
			long long mx = -4000000010L;

			for(int i=0; i<n; i++){
				mx = max(mx, a[i]);
			}

			for(int i=0; i<n; i++){
				a[i] = mx - a[i];
				b[x][i] = a[i];
			}

			// for(int i=0; i<n; i++){
			// 	printf("%lld ", a[i]);
			// }
			// printf("\n");
		}

		k--;
		for(int i=0; i<n; i++){
			if(i != 0){
				printf(" ");
			}
			printf("%lld", b[k%2][i]);
		}
		printf("\n");
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>

using namespace std;

int nt, n, k;
long long a[100010];
long long b[2][100010];

int main(){
	scanf("%d", &nt);
	for(int t=0; t<nt; t++){
		scanf("%d %d", &n, &k);

		long long mx = 0;
		for(int i=0; i<n; i++){
			scanf("%lld", &a[i]);
		}

		// printf("====\n");
		for(int x=0; x<2; x++){
			// for(int i=0; i<n; i++){
			// 	printf("%lld ", a[i]);
			// }
			// printf("\n");

			long long mx = 0;
			for(int i=0; i<n; i++){
				mx = max(mx, a[i]);
			}

			for(int i=0; i<n; i++){
				a[i] = mx - a[i];
				b[x][i] = a[i];
			}
		}

		for(int i=0; i<n; i++){
			if(i != 0){
				printf(" ");
			}
			printf("%lld", b[(k+1)%2][i]);
		}
		printf("\n");
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>

using namespace std;

int nt, n, k;
long long a[200010];
long long b[2][200010];

int main(){
	scanf("%d", &nt);
	for(int t=0; t<nt; t++){
		scanf("%d %d", &n, &k);

		for(int i=0; i<n; i++){
			scanf("%lld", &a[i]);
		}

		// printf("====\n");
		for(int x=0; x<2; x++){
			long long mx = -2000000010;

			for(int i=0; i<n; i++){
				mx = max(mx, a[i]);
			}

			for(int i=0; i<n; i++){
				a[i] = mx - a[i];
				b[x][i] = a[i];
			}

			// for(int i=0; i<n; i++){
			// 	printf("%lld ", a[i]);
			// }
			// printf("\n");
		}

		k--;
		for(int i=0; i<n; i++){
			if(i != 0){
				printf(" ");
			}
			printf("%lld", b[k%2][i]);
		}
		printf("\n");
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>

using namespace std;

int nt, n, k;
long long a[100010];
long long b[2][100010];

int main(){
	scanf("%d", &nt);
	for(int t=0; t<nt; t++){
		scanf("%d %d", &n, &k);

		for(int i=0; i<n; i++){
			scanf("%lld", &a[i]);
		}

		// printf("====\n");
		for(int x=0; x<2; x++){
			long long mx = -1000000010;

			for(int i=0; i<n; i++){
				mx = max(mx, a[i]);
			}

			for(int i=0; i<n; i++){
				a[i] = mx - a[i];
				b[x][i] = a[i];
			}

			// for(int i=0; i<n; i++){
			// 	printf("%lld ", a[i]);
			// }
			// printf("\n");
		}

		for(int i=0; i<n; i++){
			if(i != 0){
				printf(" ");
			}
			printf("%lld", b[(k+1)%2][i]);
		}
		printf("\n");
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>

using namespace std;

int nt, n;
long long k;
long long a[200010];
long long b[2][200010];

int main(){
	scanf("%d", &nt);
	for(int t=0; t<nt; t++){
		scanf("%d %lld", &n, &k);

		for(int i=0; i<n; i++){
			scanf("%lld", &a[i]);
		}

		// printf("====\n");
		for(int x=0; x<2; x++){
			long long mx = -2000000010;

			for(int i=0; i<n; i++){
				mx = max(mx, a[i]);
			}

			for(int i=0; i<n; i++){
				a[i] = mx - a[i];
				b[x][i] = a[i];
			}

			// for(int i=0; i<n; i++){
			// 	printf("%lld ", a[i]);
			// }
			// printf("\n");
		}

		k--;
		for(int i=0; i<n; i++){
			if(i != 0){
				printf(" ");
			}
			printf("%lld", b[k%2][i]);
		}
		printf("\n");
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int t;
int n;
long long k;
int a[200005];
int mn;
int mx;

int main(void){
	cin >> t;
	for (int c1 =0 ; c1 < t; c1++){
		cin >> n >> k;
		mn = 1000000001;
		mx =-1000000001;
		for (int c2 =0; c2 < n; c2++){
			cin >> a[c2];
			if (mn > a[c2]){
				mn = a[c2];
			}
			if (mx < a[c2]){
				mx = a[c2];
			}
		}
		if (k % 2 == 1){
			for (int c2 = 0; c2 < n; c2++){
				cout << mx - a[c2];
				if (c2 != n - 1){
					cout << " ";
				}
			}
			cout << endl;
		}else if (k % 2 == 0){
				for (int c2 = 0; c2 < n; c2++){
					cout << a[c2] - mn;
					if (c2 != n - 1){
						cout << " ";
					}
				}
				cout << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int t;
int n;
int k;
int a[200005];
int min;
int max;

int main(void){
	cin >> t;
	for (int c1 =0 ; c1 < t; c1++){
		cin >> n >> k;
		min = 1000000001;
		max =-1000000001;
		for (int c2 =0; c2 < n; c2++){
			cin >> a[c2];
			if (min > a[c2]){
				min = a[c2];
			}
			if (max < a[2]){
				max = a[c2];
			}
		}
		if (k % 2 == 1){
			if (k == 1){
				for (int c2 = 0; c2 < n; c2++){
					cout << a[c2] - max << " ";
				}
				cout << endl;
			}else{
				for (int c2 = 0; c2 < n; c2++){
					cout << (max - min) - (a[c2] - min) << " ";
				}
				cout << endl;
			}
		}else if (k % 2 == 0){
				for (int c2 = 0; c2 < n; c2++){
					cout << a[c2] - min << " ";
				}
				cout << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int t;
int n;
long long k;
int a[200005];
int mn;
int mx;

int main(void){
	cin >> t;
	for (int c1 =0 ; c1 < t; c1++){
		cin >> n >> k;
		mn = 1000000001;
		mx =-1000000001;
		for (int c2 =0; c2 < n; c2++){
			cin >> a[c2];
			if (mn > a[c2]){
				mn = a[c2];
			}
			if (mx < a[2]){
				mx = a[c2];
			}
		}
		if (k % 2 == 1){
			for (int c2 = 0; c2 < n; c2++){
				cout << mx - a[c2];
				if (c2 != n - 1){
					cout << " ";
				}
			}
			cout << endl;
		}else if (k % 2 == 0){
				for (int c2 = 0; c2 < n; c2++){
					cout << a[c2] - mn;
					if (c2 != n - 1){
						cout << " ";
					}
				}
				cout << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int main(){
    int a;
    cin>>a;
    while(a--){
        long long b,c, e;
        vector<long long> d;
        cin>>b>>e;
        for(int i=0;i<b;i++){
            cin>>c;
            d.push_back(c);
        }
        if(b>3){
            e= e%(b-2);
        }
        while(e--){
            long long maxi=INT_MIN;
            for(int i =0;i<b;i++){
                maxi=max(maxi,d[i]);
            }
            for(int i =0;i<b;i++){
                d[i]=maxi-d[i];
            }
        }
        for(int i =0;i<b;i++){
            cout<<d[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int main(){
    int a;
    cin>>a;
    while(a--){
        long long b,c, e;
        vector<long long> d;
        cin>>b>>e;
        for(int i=0;i<b;i++){
            cin>>c;
            d.push_back(c);
        }

        while(e--){
            long long maxi=INT_MIN;
            for(int i =0;i<b;i++){
                maxi=max(maxi,d[i]);
            }
            for(int i =0;i<b;i++){
                d[i]=maxi-d[i];
            }
        }
        for(int i =0;i<b;i++){
            cout<<d[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int main(){
    int a;
    cin>>a;
    while(a--){
        long long b,c, e,g;
        vector<long long> d;
        cin>>b>>e;
        for(int i=0;i<b;i++){
            cin>>c;
            d.push_back(c);
        }
        if(b>6){
            e= e%(b-6);
        }
        g=e;
        if(g%2)
        while(e--){
            long long maxi=INT_MIN;
            for(int i =0;i<b;i++){
                maxi=max(maxi,d[i]);
            }
            for(int i =0;i<b;i++){
                d[i]=maxi-d[i];
            }
        }
        for(int i =0;i<b;i++){
            cout<<d[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int main(){
    int a;
    cin>>a;
    while(a--){
        long long b,c, e,g;
        vector<long long> d;
        cin>>b>>e;
        for(int i=0;i<b;i++){
            cin>>c;
            d.push_back(c);
        }
        if(b>2){
            e= e%(2*(b-2));
        }
        else{
            e= e%2+2;
        }
        while(e--){
            long long maxi=INT_MIN;
            for(int i =0;i<b;i++){
                maxi=max(maxi,d[i]);
            }
            for(int i =0;i<b;i++){
                d[i]=maxi-d[i];
            }
        }
        for(int i =0;i<b;i++){
            cout<<d[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int main(){
    int a;
    cin>>a;
    while(a--){
        long long b,c, e,g;
        vector<long long> d;
        cin>>b>>e;
        for(int i=0;i<b;i++){
            cin>>c;
            d.push_back(c);
        }
        e=(e%2)+2;
        while(e--){
            long long maxi=INT_MIN;
            for(int i =0;i<b;i++){
                maxi=max(maxi,d[i]);
            }
            for(int i =0;i<b;i++){
                d[i]=maxi-d[i];
            }
        }
        for(int i =0;i<b;i++){
            cout<<d[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(2*n-1);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(q*n);
        while(x--)
        {
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(q*n);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,count;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        long long int a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        if(k%2) k=1;
        else k=2;
        for(j=0;j<k;j++)
        {
            m=INT_MIN;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%200000;
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(q*q);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=(k%n)%q;
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //a[i]=m-a[i];
                p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(2<<q);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,count;
    cin>>t;
    while(t--)
    {
        m=0;
        cin>>n>>k;
        long long int a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        if(k%2) k=1;
        else k=2;
        for(j=0;j<k;j++)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,count;
    cin>>t;
    while(t--)
    {
        m=0;
        cin>>n>>k;
        long long int a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        while(k--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(n>>1);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%q;
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(m*m);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,count;
    cin>>t;
    while(t--)
    {
        m=0;
        cin>>n>>k;
        long long int a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        x=k%(k/n);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,count;
    cin>>t;
    while(t--)
    {
        m=INT_MIN;
        cin>>n>>k;
        long long int a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        if(k%2) k=1;
        else k=2;
        for(j=0;j<k;j++)
        {

            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(n*n);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%q;
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                a[i]=m-a[i];
                //p=min(p,a[i]);
            }
            /*for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }*/
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,count;
    cin>>t;
    while(t--)
    {
        m=0;
        cin>>n>>k;
        long long int a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
if(k%2) k=1; else k=2;
        while(k--)
        {

            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(2*n);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=(k%q)%n;
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=(n*k)%k;
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=(n*k)/m;
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(2<<n);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,t,n,m,x,y,j,sum,k,p,count,q;
    cin>>t;
    while(t--)
    {
        m=0,p=INT_MAX;
        cin>>n>>k;

        long long int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
            m=max(m,a[i]);
                p=min(p,a[i]);
        }
        q=m-p;
        if(q==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        x=k%(n);
        while(x--)
        {
            m=0;
            for(i=0;i<n;i++)
            {
                m=max(m,a[i]);
                //p=min(p,a[i]);
            }
            for(i=0;i<n;i++)
            {
                a[i]=m-a[i];
            }
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(string s){
    int n=s.size();
    vector<int> score;
    int count=0;
    for (size_t i = 0; i < n; i++)
    {
        if(s[i]=='1')
            count++;
        if(s[i]=='0' && s[i-1]=='1')
        {
            score.push_back(count);
            count=0;
        }
        if(i == n-1 && s[i]=='1')
            score.push_back(count);
    }
    n=score.size();
    count=0;
    sort(score.begin(),score.end(),greater<int>());
    for (size_t i = 0; 2*i < n ; i++)
        count+=score[2*i];

    cout << count << endl;;

}

int main(){
    int T,n;
    cin >> T;
    string s;
    while (T--)
    {
        cin >> s;
        solve(s);
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<long> &a,int n,int k){
    if(k==0)
        return;
    long max=*max_element(a.begin(),a.end());
    long min=*min_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= max - a[i];
    max=max-min;
    if(k%2==1)
        return;

    for (size_t i = 0; i < n; i++)
       a[i]= max - a[i];
}

int main(){
    int t;
    cin >> t;
    int n,k;
    vector<long> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &a,int n,int k){
    if(k==0)
        return;
    int max=*max_element(a.begin(),a.end());
    int min=*min_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= max - a[i];
    max=max-min;
    if(k%2==1)
        return;

    for (size_t i = 0; i < n; i++)
       a[i]= max - a[i];
}

int main(){
    int t;
    cin >> t;
    int n,k;
    vector<int> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &a,int n,long long k){
    if(k==0)
        return;
    int max=*max_element(a.begin(),a.end());
    int min=*min_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= max - a[i];
    max=max-min;
    if(k%2==1)
        return;

    for (size_t i = 0; i < n; i++)
       a[i]= max - a[i];
}

int main(){
    int t;
    cin >> t;
    int n;
    long long k;
    vector<int> a;
    while (t--){
        cin >> n ;
        cin >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<long> &a,int n,int k){
    if(k==0)
        return;
    int max=*max_element(a.begin(),a.end());
    int min=*min_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= max - a[i];
    max=max-min;
    if(k%2==1)
        return;
    else
    {
        for (size_t i = 0; i < n; i++)
            a[i]= max - a[i];
    }
}

int main(){
    int t;
    cin >> t;
    int n,k;
    vector<long> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &a,int n,int k){
    if(k=0)
        return;
    int num=*max_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= num - a[i];

}

int main(){
    int t;
    cin >> t;
    int n,k;
    vector<int> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &a,int n,int k){
    int max=*max_element(a.begin(),a.end());
    int min=*min_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= max - a[i];
    max=max-min;
    if(k%2==1)
        return;
    else
    {
        for (size_t i = 0; i < n; i++)
            a[i]= max - a[i];
    }
}

int main(){
    int t;
    cin >> t;
    int n,k;
    vector<int> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &a,int n,long k){
    if(k==0)
        return;
    int max=*max_element(a.begin(),a.end());
    int min=*min_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= max - a[i];
    max=max-min;
    if(k%2==1)
        return;

    for (size_t i = 0; i < n; i++)
       a[i]= max - a[i];
}

int main(){
    int t;
    cin >> t;
    int n;
    long k;
    vector<int> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &a,int n,int k){
    if(k==0)
        return;
    int num=*max_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= num - a[i];

    solve(a,n,k-1);
}

int main(){
    int t;
    cin >> t;
    int n,k;
    vector<int> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<long> &a,int n,int k){
    if(k==0)
        return;
    long max=*max_element(a.begin(),a.end());
    long min=*min_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= max - a[i];
    max=max-min;
    if(k%2==1)
        return;

    for (size_t i = 0; i < n; i++)
       a[i]= max - a[i];
}

int main(){
    int t;
    cin >> t;
    int n;
    long k;
    vector<long> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void solve(vector<long> &a,int n,int k){
    int max=*max_element(a.begin(),a.end());
    int min=*min_element(a.begin(),a.end());
    for (size_t i = 0; i < n; i++)
        a[i]= max - a[i];
    max=max-min;
    if(k%2==1)
        return;
    else
    {
        for (size_t i = 0; i < n; i++)
            a[i]= max - a[i];
    }
}

int main(){
    int t;
    cin >> t;
    int n,k;
    vector<long> a;
    while (t--){
        cin >> n >> k;
        a.resize(n);
        for (size_t i = 0; i < n; i++)
            cin >> a[i];
        solve(a,n,k);
        for (size_t i = 0; i < n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main () {
    int t;
    cin >> t;
    while (t--) {
        long long int n, k, d = 0, dd = 0;
        cin >> n >> k;
        vector<long long int> a(n), b(n), c(n);
        cin >> a[0];
        d = a[0];
        for (int i = 1; i < n; i++) {
            cin >> a[i];
            if (d < a[i]) {
                d = a[i];
            }
        }
        dd = d-a[0];
        for (int i = 0; i < n; i++) {
            b[i] = d-a[i];
            if (dd < b[i]) {
                dd = b[i];
            }
        }
        for (int i = 0; i < n; i++) {
            c[i] = dd-b[i];
        }
        if (k == 0) {
            for (long long int x : a) {
                cout << x << " ";
            }
            cout << "\n";
        }else if (k % 2 == 0) {
            for (long long int x : c) {
                cout << x << " ";
            }
            cout << "\n";
        }else {
            for (long long int x : b) {
                cout << x << " ";
            }
            cout << "\n";
        }
        // while (k--) {
        //     d = a[0];
        //     for (long long int x : a) {
        //         if (d < x) d = x;
        //     }
        //     for (long long int & x : a) {
        //         x = d - x;
        //     }
        // }
        // for (long long int x : a) {
        //     cout << x << " ";
        // }
        // cout << "\n";
    }
}