/* Problem URL: https://codeforces.com/problemset/problem/2021/C2 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;

#define V vector

#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)

#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)

#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;

using ll = long long;

using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;

template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
    os << vec[0];
    for (size_t i = 1; i < vec.size(); i++) {
        os << ' ' << vec[i];
    }
    os << '\n';
    return os;
}

template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
    for (auto &i : vec) {
        is >> i;
    }
    return is;
}

template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
    for (auto &i : vec) {
        os << i[0];
        for (size_t j = 1; j < i.size(); j++) {
            os << ' ' << i[j];
        }
        os << '\n';
    }
    return os;
}

template<class v>
auto operator>>(istream  &is, vector<vector<v>> &vec)->istream& {
    for (auto &i : vec) {
        for (auto &j : i) {
            is >> j;
        }
    }
    return is;
}

const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;


void pre()
{

}

#define TEST 1

void solve()
{
    int n, m, q;
    cin >> n >> m >> q;

    vi a(n);
    cin >> a;

    vi var(n);
    V<set<int>> ap(n);
    rep(i, n) {
        var[a[i] - 1] = i;
        ap[i].insert(oo);
    }

    vi b(m);
    rep(i, m) {
        cin >> b[i];
        ap[var[b[i] - 1]].insert(i);
    }

    int sz = n;
    while (__builtin_popcount(sz) != 1) {
        sz++;
    }

    V<ordered_set<pair<int, int>>> seg(sz * 2);
    vl sum(sz * 2);
    nrep(i, sz, sz * 2) {
        seg[i].insert({oo, i - sz});
    }

    for (int i = sz - 1; i > 0; i--) {
        repv(j, seg[i * 2]) {
            seg[i].insert(j);
        }
        repv(j, seg[i * 2 + 1]) {
            seg[i].insert(j);
        }
    }

    auto update = [&](int i, int v) {
        int ind = i;
        i += sz;
        auto bf = *seg[i].begin();
        seg[i].clear();
        seg[i].insert({v, i - sz});
        int now = i & 1;
        int dd = 0;

        for (i >>= 1; i > 0; i >>= 1) {
            seg[i].erase(bf);
            seg[i].insert({v, ind});
            sum[i] += dd;

            if (now) {
                int s = seg[i * 2].size() - seg[i * 2].order_of_key({v, oo});
                int s2 = seg[i * 2].size() - seg[i * 2].order_of_key({bf.first, oo});
                sum[i] -= s2;
                sum[i] += s;
                dd -= s2;
                dd += s;
            } else {
                int s = seg[i * 2 + 1].order_of_key({v, -1});
                int s2 = seg[i * 2 + 1].order_of_key({bf.first, -1});
                sum[i] -= s2;
                sum[i] += s;
                dd -= s2;
                dd += s;
            }

            now = i & 1;
        }
    };

    rep(i, n) {
        update(i, *ap[i].begin());
    }

    auto check = [&]() {
        string ans[] = {
            "TIDAK",
            "YA"
        };
        cout << ans[sum[1] == 0] << '\n';
    };

    check();
    while (q--) {
        int i, j;
        cin >> i >> j;
        i--;

        int bf = b[i];
        b[i] = j;
        int actbf = var[bf - 1];
        int actb = var[b[i] - 1];

        ap[actbf].erase(i);
        ap[actb].insert(i);
        update(actbf, *ap[actbf].begin());
        update(actb, *ap[actb].begin());
        check();
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    pre();

    int t;
    (TEST && cin >> t) || (t = 1);
    while (t--) {
        solve();
    }
}
