#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/exception.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/list_update_policy.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ldb;
#define umap __gnu_pbds::cc_hash_table
#define mkp make_pair
#define prque priority_queue
#define emp emplace
#define empb emplace_back
#define empf emplace_front
random_device rndv;
mt19937 rd(rndv());
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const vector<ll> millerrabin = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
const double eps = 1e-8;
inline void enter(){putchar('\n');}
inline void space(){putchar(' ');}
inline ll readll(){ll ret=0,k=1;char c;do{c=getchar();if(c=='-'){k=-1;}}while(('0'>c)|('9'<c));do{ret=(ret<<3)+(ret<<1)+c-48;c=getchar();}while(('0'<=c)&(c<='9'));return ret*k;}
inline void read(ll&x){x=readll();}
inline char readchar(){char ret;do{ret=getchar();}while(ret<=32);return ret;}
inline void read(char&x){x=readchar();}
inline string readstr(){string ret;char c;do{c=getchar();}while(c<=32);do{ret+=c;c=getchar();}while((c>32)&(c!=EOF));return ret;}
inline void read(string&x){x=readstr();}
inline void write(ll x){if(!x){putchar('0');return;}if(x<0){putchar('-');x*=-1;}char op[20]={};ll cur=0;while(x){op[++cur]=x%10+48;x/=10;}while(cur){putchar(op[cur--]);}}
inline ostream& operator<<(ostream& out, __int128 x){if(!x){out<<"0";return out;}if(x<0){out<<"-";x*=-1;}char op[40]={};ll cur=0;while(x){op[++cur]=x%10+48;x/=10;}while(cur){out<<op[cur--];}return out;}
const ll MAXN = 2e5 + 5;
ll n = 0, m = 0, q, a[MAXN], b[MAXN], posa[MAXN];
set<ll> pos[MAXN];
struct segTree {
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
ll size = 0, lf[MAXN << 2], rg[MAXN << 2], ans[MAXN << 2];
void init(ll x) {
for (ll i = 1; i <= size; ++i) {
lf[i] = rg[i] = ans[i] = 0;
}
size = 1;
while (size < x) {
size <<= 1;
}
for (ll i = 1; i <= size * 2; ++i) {
lf[i] = rg[i] = inf;
ans[i] = 1;
}
}
void pushup(ll x) {
lf[x] = lf[l(x)], rg[x] = rg[r(x)];
if (!ans[l(x)] || !ans[r(x)] || rg[l(x)] > lf[r(x)]) {
ans[x] = 0;
} else {
ans[x] = 1;
}
}
void mdf(ll p, ll v, ll x, ll lx, ll rx) {
if (rx < p || p < lx) {
return;
}
if (p <= lx && rx <= p) {
lf[x] = rg[x] = v;
ans[x] = 1;
return;
}
ll mid = (lx + rx) >> 1;
mdf(p, v, l(x), lx, mid), mdf(p, v, r(x), mid + 1, rx);
pushup(x);
}
void mdf(ll p, ll v) {
mdf(p, v, 1, 1, size);
}
bool qry() {
return ans[1];
}
} st;
void op() {
puts(st.qry() ? "YA" : "TIDAK");
}
void init() {
for (ll i = 1; i <= m; ++i) {
a[i] = b[i] = posa[i] = 0;
pos[i].clear();
}
st.init(0);
}
int mian() {
read(n), read(m), read(q);
for (ll i = 1; i <= n; ++i) {
read(a[i]);
posa[a[i]] = i;
}
st.init(n);
for (ll i = 1; i <= m; ++i) {
read(b[i]);
b[i] = posa[b[i]];
pos[b[i]].emp(i);
}
for (ll i = 1; i <= n; ++i) {
pos[i].emp(inf);
st.mdf(i, *pos[i].begin());
}
op();
while (q--) {
ll x, y;
read(x), read(y);
y = posa[y];
ll prv = b[x];
pos[prv].erase(x);
pos[y].emp(x);
b[x] = y;
st.mdf(y, *pos[y].begin());
st.mdf(prv, *pos[prv].begin());
op();
}
return 0;
}
int main() {
ll T;
read(T);
while (T--) {
init();
mian();
}
return 0;
}