#include "bits/stdc++.h"
using namespace std;

#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    multiset<int> sum1, sum2, sub1, sub2;
    set<pair<int, int>> s1, s2;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        sum1.insert(x + y);
        sub1.insert(x - y);
        s1.insert({x, y});
    }
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        sum2.insert(x + y);
        sub2.insert(x - y);
        s2.insert({x, y});
    }
    int q;
    cin >> q;
    while (q--) {
        int type, x, y;
        cin >> type >> x >> y;
        if (type == 1) {
            if (s1.find({x, y}) != s1.end()) {
                sum1.erase(sum1.find(x + y));
                sub1.erase(sub1.find(x - y));
                s1.erase(s1.find({x, y}));
            } else {
                sum1.insert(x + y);
                sub1.insert(x - y);
                s1.insert({x, y});
            }
        } else {
            if (s2.find({x, y}) != s2.end()) {
                sum2.erase(sum2.find(x + y));
                sub2.erase(sub2.find(x - y));
                s2.erase(s2.find({x, y}));
            } else {
                sum2.insert(x + y);
                sub2.insert(x - y);
                s2.insert({x, y});
            }
        }
        if (s1.empty() || s2.empty()) {
            cout << "KAPUT\n";
            continue;
        } else {
            int val = 0;
            if (!sum1.empty() && !sum2.empty()) {
                val = max(val, *prev(sum1.end()) - *sum2.begin());
                val = max(val, *prev(sum2.end()) - *sum1.begin());
            }
            if (!sub1.empty() && !sub2.empty()) {
                val = max(val, *prev(sub1.end()) - *sub2.begin());
                val = max(val, *prev(sub2.end()) - *sub1.begin());
            }
            cout << val << '\n';
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
}
