基础题。
#include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
int M;
int x, y; //交换的位置
int pos; //字母J的位置
while (N--)
{
pos = 2;
cin >> M;
for (int i = 0; i < M; i++)
{
cin >> x >> y;
if (x == pos)
pos = y;
else if (y == pos)
pos = x;
}
cout << pos << endl;
}
return 0;
}
继续加油。