#include //const static double de_PI = 3.14159265358979323846; //const static int de_MOD = 1000000007; //const static int de_MAX = 999999999; //const static int de_MIN = -999999999; int main(void) { //std::ifstream inf("123.txt"); std::cin.rdbuf(inf.rdbuf()); int N = 0, K = 0, X = 0; std::cin >> N >> K >> X; std::vector in(N), out(N); std::vector> C(K - X, std::vector(2)); std::iota(in.begin(), in.end(), 1); int A = 0, B = 0, temp = 0; for (int i = 0; i < X - 1; i++) { std::cin >> A >> B; temp = in[A - 1]; in[A - 1] = in[B - 1]; in[B - 1] = temp; } char x = 0; std::cin >> x >> x; for (int i = K - X - 1; i >= 0; i--) { std::cin >> C[i][0] >> C[i][1]; } for (int i = 0; i < N; i++) { std::cin >> out[i]; } for (int i = 0; i < K - X; i++) { temp = out[C[i][0] - 1]; out[C[i][0] - 1] = out[C[i][1] - 1]; out[C[i][1] - 1] = temp; } int i = 0; while (in[i] == out[i]) { i++; } std::cout << i + 1 << " " << std::distance(out.begin(), std::find(out.begin(), out.end(), in[i])) + 1 << std::endl; }