#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 500;   const int LN = 21;   const long long mod = 1e9 + 7;   const long long INF = 1LL << 57;   long long n, m, u, v, k, t, q, a, x, d;   int tree[4 * N];   int sum[4 * N];   int lim = 1e6 + 2;   int arr[N], brr[N];   bool print = false;   void modify(int i, int l, int r, int index, int val) {     if (l == r) {       tree[i] += val;       sum[i] = tree[i];       return;     }     int mid = (l + r) / 2;     if (index <= mid)       modify(i + 1 + i, l, mid, index, val);     else       modify(i + 2 + i, mid + 1, r, index, val);     tree[i] = max(tree[i + 2 + i], tree[i + 1 + i] + sum[i + 2 + i]);     sum[i] = sum[i + 1 + i] + sum[i + 2 + i];   }   int find(int i, int l, int r, int sumx) {     if (l == r) return l;     int mid = (l + r) / 2;     if (tree[i + 2 + i] + sumx > 0) {       return find(i + 2 + i, mid + 1, r, sumx);     } else       return find(i + 1 + i, l, mid, sumx + sum[i + 2 + i]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> arr[i];     }     for (int i = 1; i <= m; ++i) cin >> brr[i];     for (int i = 1; i <= n; ++i) {       modify(0, 0, lim, arr[i], 1);     }     for (int i = 1; i <= m; ++i) {       modify(0, 0, lim, brr[i], -1);     }     cin >> q;     while (q--) {       int type;       cin >> type;       if (type == 1) {         int i, x;         cin >> i >> x;         modify(0, 0, lim, arr[i], -1);         modify(0, 0, lim, x, 1);         arr[i] = x;         int price = find(0, 0, lim, 0);         if (price == 0)           cout << -1 <<   n ;         else           cout << price <<   n ;       } else {         int i, x;         cin >> i >> x;         modify(0, 0, lim, brr[i], 1);         modify(0, 0, lim, x, -1);         brr[i] = x;         int price = find(0, 0, lim, 0);         if (price == 0)           cout << -1 <<   n ;         else           cout << price <<   n ;       }     }   }   