#include <iostream>
#include <type_traits>
#include <vector>
#include <cstdint>
#include <algorithm>
#include <cassert>
#include <numeric>
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0425"

using i32   = int32_t;
using i64   = int64_t;
using u32   = uint32_t;
using u64   = uint64_t;
using uint  = unsigned int;
using usize = std::size_t;
using ll    = long long;
using ull   = unsigned long long;
using ld    = long double;
template<typename T, usize n>
using arr = T (&)[n];
template<typename T, usize n>
using c_arr = const T (&)[n];
template<typename T>
T in()
{
    T v;
    return std::cin >> v, v;
}
template<typename T, typename Uint, usize n, usize i>
T in_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type) { return in<T>(); }
template<typename T, typename Uint, usize n, usize i>
auto in_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type& szs)
{
    const usize s = (usize)szs[i];
    std::vector<decltype(in_v<T, Uint, n, i + 1>(szs))> ans(s);
    for (usize j = 0; j < s; j++) { ans[j] = in_v<T, Uint, n, i + 1>(szs); }
    return ans;
}
template<typename T, typename Uint, usize n>
auto in_v(c_arr<Uint, n> szs) { return in_v<T, Uint, n, 0>(szs); }
template<typename... Types>
auto in_t() { return std::tuple<std::decay_t<Types>...>{in<Types>()...}; }

template<typename T>
void out(const T& v) { std::cout << v; }
template<typename T>
void out(const std::vector<T>& v)
{
    for (usize i = 0; i < v.size(); i++) {
        if (i > 0) { std::cout << ' '; }
        out(v[i]);
    }
    std::cout << "\n";
}
template<typename T, typename... Args>
void out(const T& v, const Args... args) { out(v), std::cout << ' ', out(args...); }
template<typename... Args>
void outln(const Args... args) { out(args...), std::cout << '\n'; }
template<typename... Args>
void outel(const Args... args) { out(args...), std::cout << std::endl; }

template<usize block_size>
class mo_manager
{
private:
    usize sz, x, y, ind;
    std::vector<usize> xs, ys, inds;

public:
    template<typename InIt>
    mo_manager(const InIt first, const InIt last) : sz(static_cast<usize>(std::distance(first, last))), x(0), y(0), ind(0), inds(sz)
    {
        for (auto it = first; it != last; it++) { xs.push_back(it->first), ys.push_back(it->second); }
        std::iota(inds.begin(), inds.end(), 0);
        std::sort(inds.begin(), inds.end(), [&](const usize i, const usize j) {
            const usize ib = xs[i] / block_size, jb = xs[j] / block_size;
            return ib != jb ? ib < jb : (ib % 2 == 0 ? ys[i] < ys[j] : ys[i] > ys[j]);
        });
    }
    template<typename F1, typename F2, typename F3, typename F4>
    usize proceed(const F1 move_right, const F2 move_left, const F3 move_down, const F4 move_up)
    {
        assert(ind < sz);
        const usize nx = xs[inds[ind]], ny = ys[inds[ind]];
        for (; x < nx; x++) { move_right(x, y); }
        for (; x > nx; x--) { move_left(x, y); }
        for (; y < ny; y++) { move_down(x, y); }
        for (; y > ny; y--) { move_up(x, y); }
        return inds[ind++];
    }
    template<typename F1, typename F2>
    usize proceed(const F1 add, const F2 del)
    {
        assert(ind < sz);
        const usize nx = xs[inds[ind]], ny = ys[inds[ind]];
        for (; x < nx; x++) { del(x); }
        for (; x > nx; x--) { add(x - 1); }
        for (; y < ny; y++) { add(y); }
        for (; y > ny; y--) { del(y - 1); }
        return inds[ind++];
    }
};
int main()
{
    const auto N = in<usize>();
    const auto K = in<usize>();
    const auto Q = in<usize>();
    std::vector<usize> a(K), b(K);
    for (usize i = 0; i < K; i++) { a[i] = in<usize>() - 1, b[i] = in<usize>() - 1; }
    using pii = std::pair<usize, usize>;
    std::vector<usize> t(Q), x(Q);
    std::vector<pii> qs(Q);
    for (usize i = 0; i < Q; i++) {
        t[i]        = in<usize>();
        qs[i].first = in<usize>() - 1, qs[i].second = in<usize>();
        x[i] = in<usize>() - 1;
    }
    mo_manager<300> mo(qs.begin(), qs.end());
    std::vector<usize> p(N), r(N);
    std::iota(p.begin(), p.end(), 0), std::iota(r.begin(), r.end(), 0);
    auto move_left = [&](const usize x, const usize y) {
        const usize av = a[x - 1], bv = b[x - 1];
        const usize ai = r[av], bi = r[bv];
        std::swap(p[ai], p[bi]), std::swap(r[av], r[bv]);
    };
    auto move_right = [&](const usize x, const usize y) {
        const usize av = a[x], bv = b[x];
        const usize ai = r[av], bi = r[bv];
        std::swap(p[ai], p[bi]), std::swap(r[av], r[bv]);
    };
    auto move_down = [&](const usize x, const usize y) {
        const usize ai = a[y], bi = b[y];
        const usize av = p[ai], bv = p[bi];
        std::swap(p[ai], p[bi]), std::swap(r[av], r[bv]);
    };
    auto move_up = [&](const usize x, const usize y) {
        const usize ai = a[y - 1], bi = b[y - 1];
        const usize av = p[ai], bv = p[bi];
        std::swap(p[ai], p[bi]), std::swap(r[av], r[bv]);
    };
    std::vector<usize> ans(Q);
    for (usize i = 0; i < Q; i++) {
        const usize id   = mo.proceed(move_right, move_left, move_down, move_up);
        const usize type = t[id];
        const usize xi   = x[id];
        ans[id]          = (type == 1 ? p : r)[xi] + 1;
    }
    for (usize i = 0; i < Q; i++) { outln(ans[i]); }
    return 0;
}



Measured memory_bytes: 12388