/* * ******************************************************************************************** * AUTHOR : Vijju123 * * Language: C++14 * * Purpose: - * * IDE used: Codechef IDE. * ******************************************************************************************** * Comments will be included in practice problems if it helps ^^ */ #include #include using namespace std; int main() { // your code goes here #ifdef JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); srand(time(NULL)); int t; cin>>t; while(t--) { int n,x,s; cin>>n>>x>>s; int currAns=x; int a,b; while(s--) { cin>>a>>b; if(a==currAns) currAns=b; else if(b==currAns) currAns=a; } cout<