#include using namespace std; typedef pair P; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k, x; cin >> n >> k >> x; vector a(n); for (int i = 0; i < n; i++) a[i] = i + 1; for (int i = 0; i < x - 1; i++) { int p, q; cin >> p >> q; p--; q--; swap(a[p], a[q]); } char ax, bx; cin >> ax >> bx; vector

memo; for (int i = x; i < k; i++) { int p, q; cin >> p >> q; p--; q--; memo.emplace_back(p, q); } vector b(n); for (int i = 0; i < n; i++) cin >> b[i]; for (auto i = memo.rbegin(), e = memo.rend(); i != e; ++i) { swap(b[i->first], b[i->second]); } vector ans; for (int i = 0; i < n; i++) { if (a[i] != b[i]) ans.emplace_back(i + 1); } cout << ans[0] << " " << ans[1] << "\n"; return 0; }