	
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#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;

using ll = long long;
using u64 = unsigned long long;
using u32 = unsigned int;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, long long>;
using pli = pair<long long, int>;
using pll = pair<long long, long long>;
template <typename T>
using uset = unordered_set<T>;
template <typename T1, typename T2>
using umap = unordered_map<T1, T2>;

template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#ifndef _DEBUG
#pragma GCC optimize("O3,unroll-loops,fast-math")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif

inline void solve() {
    int n, m;
    cin >> n >> m;
    vector<pii> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i].first >> a[i].second;
    vector<pii> b(m);
    for (int i = 0; i < m; i++)
        cin >> b[i].first >> b[i].second;
    int q;
    cin >> q;
    auto query = [&](int x, int y, vector<pii> &vec) {
        auto it = find(all(vec), pii{x, y});
        if (it == vec.end())
            vec.push_back({x, y});
        else
            vec.erase(it);
    };
    while (q--) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 1)
            query(x, y, a);
        else
            query(x, y, b);
        if (a.empty() || b.empty()) {
            cout << "KAPUT\n";
            continue;
        }
        ll ans = 0;
        for (auto [x1, y1] : a)
            for (auto [x2, y2] : b)
                ans = max(ans, (ll)abs(x1 - x2) + abs(y1 - y2));
        cout << ans << '\n';
    }
}

signed main() {
#ifdef _DEBUG
    freopen("01.dat", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
    cin >> tt;
    for (int test_id = 1; test_id <= tt; test_id++) {
#ifdef _DEBUG
        cout << "Case #" << test_id << ":\n";
#endif
        solve();
    }
    return 0;
}