#include <bits/stdc++.h>   using namespace std;   constexpr long long MOD = 1e9 + 7;   struct {     int val, lazy;   } tree[4 * 1000010];   int bal(int p) { return tree[p].val + tree[p].lazy; }   void ins(int S, int val, int L = 1, int R = 1000000, int p = 1) {     if (S < L || R < 1) return;     if (1 <= L && R <= S) {       tree[p].lazy += val;       return;     }     tree[2 * p].lazy += tree[p].lazy;     tree[2 * p + 1].lazy += tree[p].lazy;     tree[p].lazy = 0;     int M = (L + R) / 2;     ins(S, val, L, M, 2 * p);     ins(S, val, M + 1, R, 2 * p + 1);     tree[p].val = max(bal(2 * p), bal(2 * p + 1));   }   int query(int L = 1, int R = 1000000, int p = 1) {     if (L == R) {       return bal(p) > 0 ? L : -1;     }     int M = (L + R) / 2;     tree[2 * p].lazy += tree[p].lazy;     tree[2 * p + 1].lazy += tree[p].lazy;     tree[p].val += tree[p].lazy;     tree[p].lazy = 0;     if (bal(2 * p + 1) > 0) return query(M + 1, R, 2 * p + 1);     return query(L, M, 2 * p);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<int> a[2];     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       a[0].push_back(x);       ins(x, 1);     }     for (int i = 0; i < m; ++i) {       int x;       scanf( %d , &x);       a[1].push_back(x);       ins(x, -1);     }     int q;     scanf( %d , &q);     while (q--) {       int idx, i, x;       scanf( %d%d%d , &idx, &i, &x);       --i;       --idx;       if (idx == 0) {         ins(a[idx][i], -1);         ins(x, 1);       } else {         ins(a[idx][i], 1);         ins(x, -1);       }       a[idx][i] = x;       printf( %d n , query());     }     return 0;   }   