#include using namespace std; using ll = long long; using vl = vector; using vvl = vector; using vvvl = vector; #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) x.begin(), x.end() constexpr ll dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; constexpr ll dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(15); } } init; template ostream& operator<<(ostream& os, const pair& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template ostream& operator<<(ostream& os, const vector& vec) { os << "["; rep(i, vec.size()) { os << vec[i]; if (i != vec.size() - 1) os << ", "; } os << "]"; return os; } template ostream& operator<<(ostream& os, const vector>& vec) { os << "["; rep(i, vec.size()) { os << vec[i]; if (i != vec.size() - 1) os << ", "; } os << "]"; return os; } #include using namespace atcoder; using mint = modint998244353; vl f(vl& a1, vl& a2) { vl nex = {}; rep(i, a1.size()) { nex.push_back(a2[a1[i]]); } return nex; } const ll BLOCK_SIZE = 200; vvl cache = {}; vector> items; ll getArrM(ll x, ll idx) { vl res = cache[x / BLOCK_SIZE]; for (int i = x / BLOCK_SIZE * BLOCK_SIZE; i < x; i++) { swap(res[items[i].first - 1], res[items[i].second - 1]); } return res[idx]; }; // @title Timer struct Timer { Timer(int ms) : dur(ms), st(chrono::steady_clock::now()) {} bool isTimeOver() const { auto cur = chrono::steady_clock::now(); auto e = chrono::duration_cast(cur - st).count(); return e >= dur; } int dur; chrono::steady_clock::time_point st; }; int main() { Timer timer(1950); ll n, m, q; cin >> n >> m >> q; items.resize(m); rep(i, m) cin >> items[i].first >> items[i].second; vl last(n); rep(i, n) last[i] = i; rep(i, m) { if (i % BLOCK_SIZE == 0) { cache.push_back(last); } swap(last[items[i].first - 1], last[items[i].second - 1]); } vvl db = {last}; rep(i, 60) { db.push_back(f(db.back(), db.back())); } rep(i, q) { if (timer.isTimeOver()) { break; } ll t, x; cin >> t >> x; ll rest = t % m; ll now = (t - rest) / m; ll pos = getArrM(rest, x - 1); rep(i, 60) { if (now % 2) { pos = db[i][pos]; } now /= 2; } cout << pos + 1 << endl; } return 0; }