wrong output

why it is producing wrong answer?
Link for the question is https://www.codechef.com/SEPT18B/problems/MAGICHF

`#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a1[101];
int main() {

ll t,n,x,s,x1,a,b,i,j;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>t;

for(j=0;j<t;j++)
{cin>>n>>x>>s;
for(i=0;i<s;i++)
{cin>>a>>b;
if(x==a)
x=b;
else if(x==b)
x=a;
}
a1[j]=x;}

for(i=0;i<t;i++)
cout<<a1[i];
return 0;
}#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a1[101];
int main() {

ll t,n,x,s,x1,a,b,i,j;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>t;

for(j=0;j<t;j++)
{cin>>n>>x>>s;
for(i=0;i<s;i++)
{cin>>a>>b;
if(x==a)
x=b;
else if(x==b)
x=a;
}
a1[j]=x;}

for(i=0;i<t;i++)
cout<<a1[i];
return 0;
}’

//