#include #include #include #include int main() { int n, k, x; std::cin >> n >> k >> x; std::vector v(n), totyuu(n), c(n); for (int i = 0; i < n; i++) { v[i] = i + 1; } for (int i = 0; i < k; i++) { std::string a, b; std::cin >> a >> b; if (a == "?") { totyuu = v; } else { int aa = std::stoi(a) - 1, bb = std::stoi(b) - 1; std::swap(v[aa], v[bb]); } } for (int i = 0; i < n; i++) { std::cin >> c[i]; } int w1 = -1, w2 = -1; for (int i = 0; i < n; i++) { //std::cout << v[i] << std::endl; if (c[i] != v[i]) { if (w1 == -1) { w1 = std::find(totyuu.begin(), totyuu.end(), c[i]) - totyuu.begin() + 1; } else { w2 = std::find(totyuu.begin(), totyuu.end(), c[i]) - totyuu.begin() + 1; } } } if (w1 > w2) std::swap(w1, w2); std::cout << w1 << " " << w2 << std::endl; return 0; }