#include #include #include using namespace std; int main(){ int n, k, x; cin >> n >> k >> x; vector a(k), b(k); for(int i = 0; i < k; i++){ if(i == x-1){ char t1, t2; cin >> t1 >> t2; }else{ cin >> a[i] >> b[i]; a[i]--; b[i]--; } } vector c(n); for(auto &it: c) cin >> it; vector v(n); for(int i = 0; i < n; i++) v[i] = i+1; for(int i = 0; i < x-1; i++) swap(v[a[i]], v[b[i]]); for(int i = k-1; i >= x; i--) swap(c[a[i]], c[b[i]]); vector ans; for(int i = 0; i < n; i++){ if(v[i] != c[i]) ans.emplace_back(i+1); } cout << ans[0] << " " << ans[1] << endl; return 0; }