#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <string.h>
// #include <bits/stdc++.h>
using namespace std;

pair<int, int> A[600001];
int i, n, m, q, left[600001], right[600001], height[600001], buffer1[600001], buffer2[600001], r = -1, a, b, c;

int updatebuffers(pair<int, int> A[], int left[], int right[], int buffer1[], int buffer2[], int r)
{
	if(left[r] == -1)
	{
		if(A[r].second == 1)
		{
			if(buffer2[right[r]] > 0)
			{
				buffer2[r] = buffer2[right[r]] - 1;
				buffer1[r] = buffer1[right[r]];
			}
			else
			{
				buffer2[r] = 0;
				buffer1[r] = buffer1[right[r]] + 1;
			}
		}
		else
		{
			buffer1[r] = buffer1[right[r]];
			buffer2[r] = buffer2[right[r]] + 1;
		}
	}
	else if(right[r] == -1)
	{
		if(A[r].second == 1)
		{
			buffer1[r] = buffer1[left[r]] + 1;
			buffer2[r] = buffer2[left[r]];
		}
		else
		{
			if(buffer1[left[r]] > 0)
			{
				buffer1[r] = buffer1[left[r]] - 1;
				buffer2[r] = buffer2[left[r]];
			}
			else
			{
				buffer1[r] = 0;
				buffer2[r] = buffer2[left[r]] + 1;
			}
		}
	}
	else
	{
		if(A[r].second == 1)
		{
			if(buffer2[right[r]] > 0)
			{
				buffer2[r] = buffer2[right[r]] - 1;
				buffer1[r] = buffer1[right[r]];
			}
			else
			{
				buffer2[r] = 0;
				buffer1[r] = buffer1[right[r]] + 1;
			}
		}
		else
		{
			buffer2[r] = buffer2[right[r]] + 1;
			buffer1[r] = buffer1[right[r]];
		}
		if(buffer2[r] >= buffer1[left[r]])
		{
			buffer2[r] -= buffer1[left[r]];
			buffer2[r] += buffer2[left[r]];
		}
		else
		{
			buffer1[r] += buffer1[left[r]] - buffer2[r];
			buffer2[r] = buffer2[left[r]];
		}
	}
}

int max(int a, int b)
{
	if(a > b)
	{
		return a;
	}
	return b;
}

int heigt(int left[], int right[], int height[], int x)
{
	if(left[x] == -1 && right[x] == -1)
	{
		return 1;
	}
	if(left[x] == -1)
	{
		return height[right[x]] + 1;
	}
	if(right[x] == -1)
	{
		return height[left[x]] + 1;
	}
	return max(height[left[x]], height[right[x]]) + 1;
}

int getbalance(int left[], int right[], int height[], int r)
{
	int balance;
	if(left[r] == -1)
	{
		balance = -height[right[r]];
	}
	else if(right[r] == -1)
	{
		balance = height[left[r]];
	}
	else
	{
		balance = height[left[r]] - height[right[r]];
	}

	return balance;
}

int leftrotate(pair<int, int> A[], int left[], int right[], int height[], int buffer1[], int buffer2[], int x)
{
	int y, T2;
	y = right[x];
	T2 = left[y];
	left[y] = x;
	right[x] = T2;
	height[x] = heigt(left, right, height, x);
	updatebuffers(A, left, right, buffer1, buffer2, x);
	height[y] = heigt(left, right, height, y);
	updatebuffers(A, left, right, buffer1, buffer2, y);
	return y;
}

int rightrotate(pair<int, int> A[], int left[], int right[], int height[], int buffer1[], int buffer2[], int y)
{
	int x, T2;
	x = left[y];
	T2 = right[x];
	right[x] = y;
	left[y] = T2;
	height[y] = heigt(left, right, height, y);
	updatebuffers(A, left, right, buffer1, buffer2, y);
	height[x] = heigt(left, right, height, x);
	updatebuffers(A, left, right, buffer1, buffer2, x);
	return x;
}

bool more(pair<int, int> A[], int index, int r)
{
	if(A[index].first > A[r].first)
	{
		return true;
	}
	else if(A[index].first < A[r].first)
	{
		return false;
	}
	else if(A[index].second > A[r].second)
	{
		return true;
	}
	else if(A[index].second < A[r].second)
	{
		return false;
	}
	else if(index > r)
	{
		return true;
	}
	else
	{
		return false;
	}
}

int insert(pair<int, int> A[], int left[], int right[], int height[], int buffer1[], int buffer2[], int index, int r)
{
	int balance;
	if(r == -1)
	{
		r = index;
		left[r] = -1;
		right[r] = -1;
		height[r] = 1;
		if(A[index].second == 1)
		{
			buffer1[r] = 1;
			buffer2[r] = 0;
		}
		else
		{
			buffer1[r] = 0;
			buffer2[r] = 1;
		}
		return r;
	}
	if(more(A, index, r))
	{
		right[r] = insert(A, left, right, height, buffer1, buffer2, index, right[r]);
	}
	else
	{
		left[r] = insert(A, left, right, height, buffer1, buffer2, index, left[r]);
	}
	if(left[r] == -1)
	{
		height[r] = height[right[r]] + 1;
		balance = -height[right[r]];
	}
	else if(right[r] == -1)
	{
		height[r] = height[left[r]] + 1;
		balance = height[left[r]];
	}
	else
	{
		height[r] = max(height[left[r]], height[right[r]]) + 1;
		balance = height[left[r]] - height[right[r]];
	}

	updatebuffers(A, left, right, buffer1, buffer2, r);

	if(balance > 1 && more(A, left[r], index))
	{
		return rightrotate(A, left, right, height, buffer1, buffer2, r);
	}

	if(balance < -1 && more(A, index, right[r]))
	{
		return leftrotate(A, left, right, height, buffer1, buffer2, r);
	}

	if(balance > 1 && more(A, index, left[r]))
	{
		left[r] = leftrotate(A, left, right, height, buffer1, buffer2, left[r]);
		return rightrotate(A, left, right, height, buffer1, buffer2, r);
	}

	if(balance < -1 && more(A, right[r], index))
	{
		right[r] = rightrotate(A, left, right, height, buffer1, buffer2, right[r]);
		return leftrotate(A, left, right, height, buffer1, buffer2, r);
	}

	return r;
}

int minvalnode(int left[], int r)
{
	int current = r;
	while(left[current] != -1)
	{
		current = left[current];
	}

	return current;
}

int del(pair<int, int> A[], int left[], int right[], int height[], int buffer1[], int buffer2[], int index, int r)
{
	// printf("Check 1: %d, %d\n", index, r);
	int temp, balance;
	if(r == -1)
	{
		return r;
	}

	if(more(A, index, r))
	{
		right[r] = del(A, left, right, height, buffer1, buffer2, index, right[r]);
	}
	else if(more(A, r, index))
	{
		left[r] = del(A, left, right, height, buffer1, buffer2, index, left[r]);
	}
	else
	{
		if(left[r] == -1 || right[r] == -1)
		{
			if(left[r] == -1)
			{
				temp = right[r];
			}
			else
			{
				temp = left[r];
			}
			r = temp;
		}
		else
		{
			temp = minvalnode(left, right[r]);
			right[temp] = del(A, left, right, height, buffer1, buffer2, temp, right[r]);
			left[temp] = left[r];
			height[temp] = height[r];
			r = temp;
		}
	}

	if(r == -1)
	{
		return r;
	}

	if(left[r] == -1)
	{
		height[r] = height[right[r]] + 1;
		balance = -height[right[r]];
	}
	else if(right[r] == -1)
	{
		height[r] = height[left[r]] + 1;
		balance = height[left[r]];
	}
	else
	{
		height[r] = max(height[left[r]], height[right[r]]) + 1;
		balance = height[left[r]] - height[right[r]];
	}

	updatebuffers(A, left, right, buffer1, buffer2, r);

	if(balance > 1 && getbalance(left, right, height, left[r]) >= 0)
	{
		return rightrotate(A, left, right, height, buffer1, buffer2, r);
	}

	if(balance > 1 && getbalance(left, right, height, left[r]) < 0)
	{
		left[r] = leftrotate(A, left, right, height, buffer1, buffer2, left[r]);
		return rightrotate(A, left, right, height, buffer1, buffer2, r);
	}

	if(balance < -1 && getbalance(left, right, height, right[r]) <= 0)
	{
		return leftrotate(A, left, right, height, buffer1, buffer2, r);
	}

	if(balance < -1 && getbalance(left, right, height, left[r]) > 0)
	{
		right[r] = rightrotate(A, left, right, height, buffer1, buffer2, right[r]);
		return leftrotate(A, left, right, height, buffer1, buffer2, r);
	}

	return r;
}

int find(pair<int, int> A[], int left[], int right[], int buffer1[], int buffer2[], int r, int count)
{
	if(r == -1)
	{
		return -1;
	}

	if(buffer1[r] <= count)
	{
		return -1;
	}
	if(right[r] != -1)
	{
		if(buffer1[right[r]] > count)
		{
			return find(A, left, right, buffer1, buffer2, right[r], count);
		}
		else if(left[r] == -1)
		{
			return A[r].first;
		}
		else if(A[r].second == 1)
		{
			if(buffer1[right[r]] == count && buffer2[right[r]] == 0)
			{
				return A[r].first;
			}
			else
			{
				return find(A, left, right, buffer1, buffer2, left[r], count - buffer1[right[r]] + buffer2[right[r]] - 1);
			}
		}
		else
		{
			return find(A, left, right, buffer1, buffer2, left[r], count - buffer1[right[r]] + buffer2[right[r]] + 1);
		}
	}
	if(left[r] == -1)
	{
		return A[r].first;
	}
	else if(A[r].second == 1)
	{
		if(count == 0)
		{
			return A[r].first;
		}
		else
		{
			return find(A, left, right, buffer1, buffer2, left[r], count - 1);
		}
	}
	else
	{
		return find(A, left, right, buffer1, buffer2, left[r], count + 1);
	}
}

int main()
{
	scanf("%d%d", &n, &m);

	for(i = 1; i <= n; i++)
	{
		scanf("%d", &A[i].first);
		A[i].second = 1;
		r = insert(A, left, right, height, buffer1, buffer2, i, r);
	}

	for(i = 1; i <= m; i++)
	{
		scanf("%d", &A[i + n].first);
		A[i + n].second = 2;
		r = insert(A, left, right, height, buffer1, buffer2, i + n, r);
	}

	scanf("%d", &q);

	while(q--)
	{
		scanf("%d%d%d", &a, &b, &c);
		r = del(A, left, right, height, buffer1, buffer2, (a - 1)*n + b, r);
		A[(a-1)*n+b].first = c;
		r = insert(A, left, right, height, buffer1, buffer2, (a - 1)*n + b, r);
		// for(i = 1; i <= n + m; i++)
		// {
		// 	printf("%d, first = %d, second = %d, left = %d, right = %d, buffer = %d, %d\n", i, A[i].first, A[i].second, left[i], right[i], buffer1[i], buffer2[i]);
		// }
		printf("%d\n", find(A, left, right, buffer1, buffer2, r, 0));
	}
	return 0;
}


#include <bits/stdc++.h>
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define endl '\n'
//#define int long long

using namespace std;

const int N = 3e5+100;
const int M = 1048576;
const ll mod = 1e9+7;
const ll MOD = 998244353;
const ld eps = 0.000000001;
const int P = 1336;
const int inf = 1e9+7;

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

vector <int> mi, add;
ll pr = 1048576;
int a[N], b[N];

void push(int v)
{
    if (add[v])
    {
        mi[v << 1] += add[v];
        mi[v << 1 | 1] += add[v];

        add[v << 1] += add[v];
        add[v << 1 | 1] += add[v];

        add[v] = 0;
    }
}

void upd(int l, int r, int v, int cl, int cr, int zn)
{
    if (r < cl || cr < l) return;
    if (cl != cr) push(v);
    if (l <= cl && cr <= r)
    {
        mi[v] += zn;
        add[v] += zn;
        return;
    }
    int mid = (cl+cr) >> 1;
    upd(l, r, v << 1, cl, mid, zn);
    upd(l, r, v << 1 | 1, mid+1, cr, zn);
    mi[v] = min(mi[v << 1], mi[v << 1 | 1]);
}

int get()
{
    int v = 1;
    int cl = 0, cr = pr-1;
    if (mi[v] >= 0) return -1;
    while (cl < cr)
    {
        int mid = (cl+cr) >> 1;
        push(v);
        if (mi[v << 1] < 0)
        {
            v = v << 1;
            cr = mid;
        }
        else
        {
            v = v << 1 | 1;
            cl = mid+1;
        }
    }
    return M - cl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n,m;
    cin >> n >> m;

    mi.resize(pr << 1);
    add.resize(pr << 1);

    for(int i = 0; i<n; i++)
    {
        int x;
        cin >> x;
        a[i] = x;
        upd(M-x, pr-1, 1, 0, pr-1, -1);
    }

    for(int i = 0; i<m; i++)
    {
        int x;
        cin >> x;
        b[i] = x;
        upd(M-x, pr-1, 1, 0, pr-1, 1);
    }

    int q;
    cin >> q;
    for(int e = 0; e<q; e++)
    {
        int t, i, x;
        cin >> t >> i >> x;
        i--;

        if (t == 1)
        {
            if (a[i] < x) upd(M-x, M-a[i]-1, 1, 0, pr-1, -1);
            else upd(M-a[i], M-x-1, 1, 0, pr-1, 1);
            a[i] = x;
        }
        else
        {
            if (b[i] < x) upd(M-x, M-b[i]-1, 1, 0, pr-1, 1);
            else upd(M-b[i], M-x-1, 1, 0, pr-1, -1);
            b[i] = x;
        }

        cout << get() << endl;

    }

}


#include <bits/stdc++.h>
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define endl '\n'
//#define int long long

using namespace std;

const int N = 3e5+100;
const int M = 1048576;
const ll mod = 1e9+7;
const ll MOD = 998244353;
const ld eps = 0.000000001;
const int P = 1336;
const int inf = 1e9+7;

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

vector <int> mi, need, add;
ll pr = 1048576;
int a[N], b[N];

void push(int v)
{
    if (need[v])
    {
        need[v] = 0;
        need[v*2] = 1;
        need[v*2+1] = 1;

        mi[v*2] += add[v];
        mi[v*2+1] += add[v];

        add[v*2] += add[v];
        add[v*2+1] += add[v];

        add[v] = 0;
    }
}

void upd(int l, int r, int v, int cl, int cr, int zn)
{
    if (r < cl || cr < l) return;
    if (cl != cr) push(v);
    if (l <= cl && cr <= r)
    {
        mi[v] += zn;
        add[v] += zn;
        need[v] = 1;
        return;
    }
    int mid = (cl+cr)/2;
    upd(l, r, v*2, cl, mid, zn);
    upd(l, r, v*2+1, mid+1, cr, zn);
    mi[v] = min(mi[v*2], mi[v*2+1]);
}

int get()
{
    int v = 1;
    int cl = 0, cr = pr-1;
    if (mi[v] >= 0) return -1;
    while (cl < cr)
    {
        int mid = (cl+cr)/2;
        push(v);
        if (mi[v*2] < 0)
        {
            v *= 2;
            cr = mid;
        }
        else
        {
            v = v*2+1;
            cl = mid+1;
        }
    }
    return M - cl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n,m;
    cin >> n >> m;

    mi.resize(2*pr);
    need.resize(2*pr);
    add.resize(2*pr);

    for(int i = 0; i<n; i++)
    {
        int x;
        cin >> x;
        a[i] = x;
        upd(M-x, pr-1, 1, 0, pr-1, -1);
    }

    for(int i = 0; i<m; i++)
    {
        int x;
        cin >> x;
        b[i] = x;
        upd(M-x, pr-1, 1, 0, pr-1, 1);
    }

    int q;
    cin >> q;
    for(int e = 0; e<q; e++)
    {
        int t, i, x;
        cin >> t >> i >> x;
        i--;

        if (t == 1)
        {
            if (a[i] < x) upd(M-x, M-a[i]-1, 1, 0, pr-1, -1);
            else upd(M-a[i], M-x-1, 1, 0, pr-1, 1);
            a[i] = x;
        }
        else
        {
            if (b[i] < x) upd(M-x, M-b[i]-1, 1, 0, pr-1, 1);
            else upd(M-b[i], M-x-1, 1, 0, pr-1, -1);
            b[i] = x;
        }

        cout << get() << endl;

    }

}


#include <bits/stdc++.h>
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define endl '\n'
//#define int long long

using namespace std;

const int N = 3e5+100;
const int M = 1048576;
const ll mod = 1e9+7;
const ll MOD = 998244353;
const ld eps = 0.000000001;
const int P = 1336;
const int inf = 1e9+7;

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

vector <int> mi, add;
ll pr = 1048576;
int a[N], b[N];

inline void push(int v)
{
    if (add[v])
    {
        mi[v << 1] += add[v];
        mi[v << 1 | 1] += add[v];

        add[v << 1] += add[v];
        add[v << 1 | 1] += add[v];

        add[v] = 0;
    }
}

inline void upd(int l, int r, int v, int cl, int cr, int zn)
{
    if (r < cl || cr < l) return;
    if (cl != cr) push(v);
    if (l <= cl && cr <= r)
    {
        mi[v] += zn;
        add[v] += zn;
        return;
    }
    int mid = (cl+cr) >> 1;
    upd(l, r, v << 1, cl, mid, zn);
    upd(l, r, v << 1 | 1, mid+1, cr, zn);
    mi[v] = min(mi[v << 1], mi[v << 1 | 1]);
}

int get()
{
    int v = 1;
    int cl = 0, cr = pr-1;
    if (mi[v] >= 0) return -1;
    while (cl < cr)
    {
        int mid = (cl+cr) >> 1;
        push(v);
        if (mi[v << 1] < 0)
        {
            v = v << 1;
            cr = mid;
        }
        else
        {
            v = v << 1 | 1;
            cl = mid+1;
        }
    }
    return M - cl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n,m;
    cin >> n >> m;

    mi.resize(pr << 1);
    add.resize(pr << 1);

    for(int i = 0; i<n; i++)
    {
        int x;
        cin >> x;
        a[i] = x;
        upd(M-x, pr-1, 1, 0, pr-1, -1);
    }

    for(int i = 0; i<m; i++)
    {
        int x;
        cin >> x;
        b[i] = x;
        upd(M-x, pr-1, 1, 0, pr-1, 1);
    }

    int q;
    cin >> q;
    for(int e = 0; e<q; e++)
    {
        int t, i, x;
        cin >> t >> i >> x;
        i--;

        if (t == 1)
        {
            if (a[i] < x) upd(M-x, M-a[i]-1, 1, 0, pr-1, -1);
            else upd(M-a[i], M-x-1, 1, 0, pr-1, 1);
            a[i] = x;
        }
        else
        {
            if (b[i] < x) upd(M-x, M-b[i]-1, 1, 0, pr-1, 1);
            else upd(M-b[i], M-x-1, 1, 0, pr-1, -1);
            b[i] = x;
        }

        cout << get() << endl;

    }

}


#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")

#define f first
#define s second
#define pb push_back
#define endl '\n'

const int N=1e6;
int t[4000005];
int lazy[4000005];

void push(int v) {
    t[v*2] += lazy[v];
    lazy[v*2] += lazy[v];
    t[v*2+1] += lazy[v];
    lazy[v*2+1] += lazy[v];
    lazy[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int addend) {
    if (l > r)
        return;
    if (l == tl && tr == r) {
        t[v] += addend;
        lazy[v] += addend;
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = max(t[v*2], t[v*2+1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (l <= tl && tr <= r)
        return t[v];
    push(v);
    int tm = (tl + tr) / 2;
    return max(query(v*2, tl, tm, l, min(r, tm)),
               query(v*2+1, tm+1, tr, max(l, tm+1), r));
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m;
	cin>>n>>m;
	int a[n];
	int b[m];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	for(int i=0; i<m; i++){
		cin>>b[i];
	}
	for(int i=0; i<n; i++){
		update(1, 0, N, 0, a[i], 1);
	}
	for(int i=0; i<m; i++){
		update(1, 0, N, 0, b[i], -1);
	}
	int q;
	cin>>q;
	while(q--){
		int ty;
		cin>>ty;
		if(ty==1){
			int i, x;
			cin>>i>>x;
			i--;
			update(1, 0, N, 0, a[i], -1);
			update(1, 0, N, 0, x, 1);
			a[i]=x;
		}
		else{
			int i, x;
			cin>>i>>x;
			i--;
			update(1, 0, N, 0, b[i], 1);
			update(1, 0, N, 0, x, -1);
			b[i]=x;
		}
		int hi=N;
		int lo=0;
		int ans=-1;
		while(lo<=hi){
			int mid=(lo+hi)/2;
			int val=query(1, 0, N, mid, N);
			if(val>0){
				ans=mid;
				lo=mid+1;
				continue;
			}
			else{
				hi=mid-1;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 1&&(cout<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
using namespace __gnu_pbds;
using rank_tree = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr long double PI = acos(-1),eps = 1e-8;
constexpr ll N = 1002525, INF = 1e18, MOD = 1000000007, K = 300;

ll seg[N<<2], laz[N<<2];
void upd(int i, ll x){seg[i] += x, laz[i] += x;}
void push(int i){
    if(!laz[i]) return;
    upd(i<<1,laz[i]);
    upd(i<<1|1,laz[i]);
    laz[i] = 0;
}
void modify(int ml,int mr,ll k,int i=1,int l=0,int r=N){
    //assert(ml <= mr);
    if(l >= mr || r <= ml) return;
    if(ml <= l && r <= mr) return upd(i,k), void();
    modify(ml,mr,k,i<<1,l,mid), modify(ml,mr,k,i<<1|1,mid,r);
    seg[i] = max(seg[i<<1], seg[i<<1|1]);
}
ll query(int i=1,int l=0,int r=N){
    push(i);
    if(seg[i] <= 0) return -1;
    if(l+1 == r) return r;
    ll res = query(i<<1|1,mid,r);
    if(res >= 0) return res;
    return query(i<<1,l,mid);
}
ll n,m,q,c,id,x;
ll a[N], b[N];
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) modify(0,a[i],1);
    for(int i = 0; i < m; i++) modify(0,b[i],-1);
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> c >> id >> x, --id;
        if(c == 1) {
            modify(0,a[id],-1);
            a[id] = x;
            modify(0,a[id],1);
        }else if(c == 2) {
            modify(0,b[id],1);
            b[id] = x;
            modify(0,b[id],-1);
        }
        cout << query() << '\n';
    }
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 1&&(cout<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
using namespace __gnu_pbds;
using rank_tree = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr long double PI = acos(-1),eps = 1e-8;
constexpr ll N = 1002525, INF = 1e18, MOD = 1000000007, K = 300;

ll seg[N<<2], laz[N<<2];
void upd(int i, ll x){seg[i] += x, laz[i] += x;}
void push(int i){
    if(!laz[i]) return;
    upd(i<<1,laz[i]);
    upd(i<<1|1,laz[i]);
    laz[i] = 0;
}
void modify(int ml,int mr,ll k,int i=1,int l=0,int r=N){
    //assert(ml <= mr);
    if(l >= mr || r <= ml) return;
    if(ml <= l && r <= mr) return upd(i,k), void();
    modify(ml,mr,k,i<<1,l,mid), modify(ml,mr,k,i<<1|1,mid,r);
    seg[i] = max(seg[i<<1], seg[i<<1|1]);
}
ll query(int i=1,int l=0,int r=N){
    if(l+1 == r) return r;
    push(i);
    if(seg[i] <= 0) return -1;
    if(seg[i<<1|1] > 0)
        return query(i<<1|1,mid,r);
    else
        return query(i<<1,l,mid);
}
ll n,m,q,c,id,x;
ll a[N], b[N];
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) modify(0,a[i],1);
    for(int i = 0; i < m; i++) modify(0,b[i],-1);
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> c >> id >> x, --id;
        if(c == 1) {
            modify(0,a[id],-1);
            a[id] = x;
            modify(0,a[id],1);
        }else if(c == 2) {
            modify(0,b[id],1);
            b[id] = x;
            modify(0,b[id],-1);
        }
        cout << query() << '\n';
    }
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 1&&(cout<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
using namespace __gnu_pbds;
using rank_tree = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr long double PI = acos(-1),eps = 1e-8;
constexpr ll N = 2002525, INF = 1e18, MOD = 1000000007, K = 300;

ll seg[N<<2], laz[N<<2];
void upd(int i, ll x){seg[i] += x, laz[i] += x;}
void push(int i){
    if(!laz[i]) return;
    upd(i<<1,laz[i]);
    upd(i<<1|1,laz[i]);
    laz[i] = 0;
}
void modify(int ml,int mr,ll k,int i=1,int l=0,int r=N){
    //assert(ml <= mr);
    if(l >= mr || r <= ml) return;
    push(i);
    if(ml <= l && r <= mr) return upd(i,k), void();
    modify(ml,mr,k,i<<1,l,mid), modify(ml,mr,k,i<<1|1,mid,r);
    seg[i] = max(seg[i<<1], seg[i<<1|1]);
}
ll query(int i=1,int l=0,int r=N){
    if(l+1 == r) return r;
    push(i);
    if(seg[i] <= 0) return -1;
    if(seg[i<<1|1] > 0)
        return query(i<<1|1,mid,r);
    else
        return query(i<<1,l,mid);
}
ll n,m,q,c,id,x;
ll a[N], b[N];
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) modify(a[i]-1,a[i],1);
    for(int i = 0; i < m; i++) modify(0,b[i],-1);
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> c >> id >> x, --id;
        if(c == 1) {
            modify(a[id]-1,a[id],-1);
            a[id] = x;
            modify(a[id]-1,a[id],1);
        }else if(c == 2) {
            modify(0,b[id],1);
            b[id] = x;
            modify(0,b[id],-1);
        }
        cout << query() << '\n';
    }
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 1&&(cout<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
using namespace __gnu_pbds;
using rank_tree = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr long double PI = acos(-1),eps = 1e-8;
constexpr ll N = 2002525, INF = 1e18, MOD = 1000000007, K = 300;

ll seg[N<<2], laz[N<<2];
void upd(int i, ll x){seg[i] += x, laz[i] += x;}
void push(int i){
    if(!laz[i]) return;
    upd(i<<1,laz[i]);
    upd(i<<1|1,laz[i]);
    laz[i] = 0;
}
void modify(int ml,int mr,ll k,int i=1,int l=0,int r=N){
    //assert(ml <= mr);
    if(l >= mr || r <= ml) return;
    push(i);
    if(ml <= l && r <= mr) return upd(i,k), void();
    modify(ml,mr,k,i<<1,l,mid), modify(ml,mr,k,i<<1|1,mid,r);
    seg[i] = max(seg[i<<1], seg[i<<1|1]);
}
ll query(int i=1,int l=0,int r=N){
    if(l+1 == r) return r;
    push(i);
    if(seg[i] <= 0) return -1;
    if(seg[i<<1|1] > 0)
        return query(i<<1|1,mid,r);
    else
        return query(i<<1,l,mid);
}
ll n,m,q,c,id,x;
ll a[N], b[N];
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) modify(0,a[i],1);
    for(int i = 0; i < m; i++) modify(0,b[i],-1);
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> c >> id >> x, --id;
        if(c == 1) {
            modify(0,a[id],-1);
            a[id] = x;
            modify(0,a[id],1);
        }else if(c == 2) {
            modify(0,b[id],1);
            b[id] = x;
            modify(0,b[id],-1);
        }
        cout << query() << '\n';
    }
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 1&&(cout<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
using namespace __gnu_pbds;
using rank_tree = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr long double PI = acos(-1),eps = 1e-8;
constexpr ll N = 1002525, INF = 1e18, MOD = 1000000007, K = 300;

ll seg[N<<2], laz[N<<2];
void upd(int i, ll x){seg[i] += x, laz[i] += x;}
void push(int i){
    upd(i<<1,laz[i]);
    upd(i<<1|1,laz[i]);
    laz[i] = 0;
}
void modify(int ml,int mr,ll k,int i=1,int l=0,int r=N){
    //assert(ml <= mr);
    if(l >= mr || r <= ml) return;
    if(l+1 != r) push(i);
    if(ml <= l && r <= mr) return upd(i,k), void();
    modify(ml,mr,k,i<<1,l,mid), modify(ml,mr,k,i<<1|1,mid,r);
    seg[i] = max(seg[i<<1], seg[i<<1|1]);
}
ll query(int i=1,int l=0,int r=N){
    push(i);
    if(seg[i] <= 0) return -1;
    if(l+1 == r) return r;
    if(seg[i<<1|1] > 0)
        return query(i<<1|1,mid,r);
    else
        return query(i<<1,l,mid);
}
ll n,m,q,c,id,x;
ll a[N], b[N];
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) modify(0,a[i],1);
    for(int i = 0; i < m; i++) modify(0,b[i],-1);
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> c >> id >> x, --id;
        if(c == 1) {
            modify(0,a[id],-1);
            a[id] = x;
            modify(0,a[id],1);
        }else if(c == 2) {
            modify(0,b[id],1);
            b[id] = x;
            modify(0,b[id],-1);
        }
        cout << query() << '\n';
    }
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 1&&(cout<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
using namespace __gnu_pbds;
using rank_tree = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr long double PI = acos(-1),eps = 1e-8;
constexpr ll N = 1002525, INF = 1e18, MOD = 1000000007, K = 300;

ll seg[N<<2], laz[N<<2];
void upd(int i, ll x){seg[i] += x, laz[i] += x;}
void push(int i){
    if(!laz[i]) return;
    upd(i<<1,laz[i]);
    upd(i<<1|1,laz[i]);
    laz[i] = 0;
}
void modify(int ml,int mr,ll k,int i=1,int l=0,int r=N){
    //assert(ml <= mr);
    if(l >= mr || r <= ml) return;
    if(ml <= l && r <= mr) return upd(i,k), void();
    modify(ml,mr,k,i<<1,l,mid), modify(ml,mr,k,i<<1|1,mid,r);
    seg[i] = max(seg[i<<1], seg[i<<1|1]);
}
ll query(int i=1,int l=0,int r=N){
    push(i);
    if(seg[i] <= 0) return -2;
    if(l+1 == r) return l;
    ll res = query(i<<1|1,mid,r);
    if(res > 0) return res;
    return query(i<<1,l,mid);
}
ll n,m,q,c,id,x;
ll a[N], b[N];
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) modify(0,a[i],1);
    for(int i = 0; i < m; i++) modify(0,b[i],-1);
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> c >> id >> x, --id;
        if(c == 1) {
            modify(0,a[id],-1);
            a[id] = x;
            modify(0,a[id],1);
        }else if(c == 2) {
            modify(0,b[id],1);
            b[id] = x;
            modify(0,b[id],-1);
        }
        cout << query()+1 << '\n';
    }
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 1&&(cout<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
using namespace __gnu_pbds;
using rank_tree = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr long double PI = acos(-1),eps = 1e-8;
constexpr ll N = 1002525, INF = 1e18, MOD = 1000000007, K = 300;

ll seg[N<<2], laz[N<<2];
void upd(int i, ll x){seg[i] += x, laz[i] += x;}
void push(int i){
    upd(i<<1,laz[i]);
    upd(i<<1|1,laz[i]);
    laz[i] = 0;
}
void modify(int ml,int mr,ll k,int i=1,int l=0,int r=N){
    if(l >= mr || r <= ml) return;
    push(i);
    if(ml <= l && r <= mr) return upd(i,k), void();
    modify(ml,mr,k,i<<1,l,mid), modify(ml,mr,k,i<<1|1,mid,r);
    seg[i] = max(seg[i<<1], seg[i<<1|1]);
}
ll query(int i=1,int l=0,int r=N){
    push(i);
    if(seg[i] <= 0) return -1;
    if(l+1 == r) return r;
    if(seg[i<<1|1] > 0)
        return query(i<<1|1,mid,r);
    else
        return query(i<<1,l,mid);
}
ll n,m,q,c,id,x;
ll a[N], b[N];
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) modify(0,a[i],1);
    for(int i = 0; i < m; i++) modify(0,b[i],-1);
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> c >> id >> x, --id;
        if(c == 1) {
            modify(0,a[id],-1);
            a[id] = x;
            modify(0,a[id],1);
        }else if(c == 2) {
            modify(0,b[id],1);
            b[id] = x;
            modify(0,b[id],-1);
        }
        cout << query() << '\n';
    }
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 1&&(cout<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
using namespace __gnu_pbds;
using rank_tree = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr long double PI = acos(-1),eps = 1e-8;
constexpr ll N = 1002525, INF = 1e18, MOD = 1000000007, K = 300;

ll seg[N<<2], laz[N<<2];
void upd(int i, ll x){seg[i] += x, laz[i] += x;}
void push(int i){
    if(!laz[i]) return;
    upd(i<<1,laz[i]);
    upd(i<<1|1,laz[i]);
    laz[i] = 0;
}
void modify(int ml,int mr,ll k,int i=1,int l=0,int r=N){
    //assert(ml <= mr);
    if(l >= mr || r <= ml) return;
    push(i);
    if(ml <= l && r <= mr) return upd(i,k), void();
    modify(ml,mr,k,i<<1,l,mid), modify(ml,mr,k,i<<1|1,mid,r);
    seg[i] = max(seg[i<<1], seg[i<<1|1]);
}
ll query(int i=1,int l=0,int r=N){
    if(l+1 == r) return r;
    push(i);
    if(seg[i] <= 0) return -1;
    if(seg[i<<1|1] > 0)
        return query(i<<1|1,mid,r);
    else
        return query(i<<1,l,mid);
}
ll n,m,q,c,id,x;
ll a[N], b[N];
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) modify(0,a[i],1);
    for(int i = 0; i < m; i++) modify(0,b[i],-1);
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> c >> id >> x, --id;
        if(c == 1) {
            modify(0,a[id],-1);
            a[id] = x;
            modify(0,a[id],1);
        }else if(c == 2) {
            modify(0,b[id],1);
            b[id] = x;
            modify(0,b[id],-1);
        }
        cout << query() << '\n';
    }
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#define LL long long
#define ls l, mid, rt << 1
#define rs mid + 1, r, rt << 1 | 1
using namespace std;

const int maxn = 1e6 + 10;
int n, m;
struct node
{
	int lazy, minn;
}tr[maxn << 2];
int a[maxn], b[maxn];
int R = 1e6;

void pushdown(int rt)
{
	if(tr[rt].lazy != 0)
	{
		tr[rt << 1].minn += tr[rt].lazy;
		tr[rt << 1 | 1].minn += tr[rt].lazy;
		tr[rt << 1].lazy += tr[rt].lazy;
		tr[rt << 1 | 1].lazy += tr[rt].lazy;
		tr[rt].lazy = 0;
	}
}
void update(int L, int R, int c, int l, int r, int rt)
{
	if(l >= L && r <= R)
	{
		tr[rt].minn += c;
		tr[rt].lazy += c;
		return;
	}
	int mid = (l + r) >> 1;
	pushdown(rt);
	if(mid >= L)
		update(L, R, c, ls);
	if(mid < R)
		update(L, R, c, rs);
	tr[rt].minn = min (tr[rt << 1].minn, tr[rt << 1 | 1].minn);
}
int query(int l, int r, int rt)
{
	if(l == r)
		return l;
	int mid = (l + r) >> 1;
	pushdown(rt);
	if(tr[rt << 1 | 1].minn < 0)
		return query(rs);
	return query(ls);
}
int main()
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i ++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= m; i ++)
		scanf("%d", &b[i]);
	for(int i = 1; i <= n; i ++)
		update(1, a[i], -1, 1, R, 1);
	for(int i = 1; i <= m; i ++)
		update(1, b[i], 1, 1, R, 1);
	int Q;
	scanf("%d", &Q);
	while(Q --)
	{
		int op, id, c;
		scanf("%d %d %d", &op, &id, &c);
		if(op == 1)
		{
			update(1, a[id], 1, 1, R, 1);
			a[id] = c;
			update(1, c, -1, 1, R, 1);
		}
		else
		{
			update(1, b[id], -1, 1, R, 1);
			b[id] = c;
			update(1, c, 1, 1, R, 1);
		}
		if(tr[1].minn >= 0)
			printf("-1\n");
		else
		{
			printf("%d\n", query(1, R, 1));
		}
	}
	return 0;
}


/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define INF 1000000000
#define MOD 1000000007
#define MO 1000000006
#define M 998244353
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
ll modExpo(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modExpo((x*x)%MOD,n/2);
    else                             //n is odd

        return (x*modExpo((x*x)%MOD,(n-1)/2))%MOD;

}
ll modInverse(ll n)
{
    return modExpo(n,MOD-2);
}
#define N 1000000
//Variables Start
ll n,m,k,ar[N],seg[4*N],lazy[4*N];
string s,s1;
//Variables End
void push(ll node,ll l,ll r)
{
    seg[node]+=lazy[node];
    if(l!=r)
    {
        lazy[2*node]+=lazy[node];
        lazy[2*node+1]+=lazy[node];
    }
    lazy[node]=0;

}
void update(ll node,ll l,ll r,ll st,ll en,ll val)
{
    push(node,l,r);
    if(l>en||r<st||l>r)return;
    if( st<=l && r<=en)
    {
        lazy[node]+=val;
        push(node,l,r);
        return;
    }
    ll mid=(l+r)>>1;
    update(2*node,l,mid,st,en,val);
    update(2*node+1,mid+1,r,st,en,val);
    seg[node]=max(seg[2*node],seg[2*node+1]);

}
ll query(ll node,ll l,ll r)
{
    push(node,l,r);
    if(l>r)return -1;
    if(l==r)return l;
    ll mid=(l+r)>>1;
    push(2*node,l,mid);
    push(2*node+1,mid+1,r);

    if(seg[2*node+1]>0)return query(2*node+1,mid+1,r);
    if(seg[2*node]>0)return query(2*node,l,mid);
    return -1;
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
        vi a,b;
        cin>>n>>m;
        rep(i,0,n)
        {
            ll x;cin>>x;
            a.pb(x);
            update(1,1,N,1,x,1);
        }
        rep(i,0,m)
        {
            ll x;cin>>x;
            b.pb(x);
            update(1,1,N,1,x,-1);
        }
        cin>>k;
        while(k--)
        {
            ll ty,ind,val;
            cin>>ty>>ind>>val;
            ind--;
            if(ty==1)
            {
                update(1,1,N,1,a[ind],-1);
                a[ind]=val;
                update(1,1,N,1,a[ind],1);
            }
            else
            {
                update(1,1,N,1,b[ind],1);
                b[ind]=val;
                update(1,1,N,1,b[ind],-1);

            }
            cout<<query(1,1,N)<<endl;
        }
    }
    return 0;

}


/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define INF 1000000000
#define MOD 1000000007
#define MO 1000000006
#define M 998244353
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
ll modExpo(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modExpo((x*x)%MOD,n/2);
    else                             //n is odd

        return (x*modExpo((x*x)%MOD,(n-1)/2))%MOD;

}
ll modInverse(ll n)
{
    return modExpo(n,MOD-2);
}
#define N 1000000
//Variables Start
ll n,m,k,ar[N],seg[4*N],lazy[4*N];
string s,s1;
//Variables End
void push(ll node,ll l,ll r)
{
    seg[node]+=lazy[node];
    if(l!=r)
    {
        lazy[2*node]+=lazy[node];
        lazy[2*node+1]+=lazy[node];
    }
    lazy[node]=0;

}
void update(ll node,ll l,ll r,ll st,ll en,ll val)
{
    push(node,l,r);
    if(l>en||r<st)return;
    if( st<=l && r<=en)
    {
        lazy[node]+=val;
        push(node,l,r);
        return;
    }
    ll mid=(l+r)>>1;
    update(2*node,l,mid,st,en,val);
    update(2*node+1,mid+1,r,st,en,val);
    seg[node]=max(seg[2*node],seg[2*node+1]);

}
ll query(ll node,ll l,ll r)
{
    push(node,l,r);
    if(l>N||r<1)return -1;
    if(l==r)return l;
    ll mid=(l+r)>>1;
    push(2*node,l,mid);
    push(2*node+1,mid+1,r);

    if(seg[2*node+1]>0)return query(2*node+1,mid+1,r);
    if(seg[2*node]>0)return query(2*node,l,mid);
    return -1;
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
        vi a,b;
        cin>>n>>m;
        rep(i,0,n)
        {
            ll x;cin>>x;
            a.pb(x);
            update(1,1,N,1,x,1);
        }
        rep(i,0,m)
        {
            ll x;cin>>x;
            b.pb(x);
            update(1,1,N,1,x,-1);
        }
        cin>>k;
        while(k--)
        {
            ll ty,ind,val;
            cin>>ty>>ind>>val;
            ind--;
            if(ty==1)
            {
                update(1,1,N,1,a[ind],-1);
                a[ind]=val;
                update(1,1,N,1,a[ind],1);
            }
            else
            {
                update(1,1,N,1,b[ind],1);
                b[ind]=val;
                update(1,1,N,1,b[ind],-1);

            }
            cout<<query(1,1,N)<<endl;
        }
    }
    return 0;

}


/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define INF 1000000000
#define MOD 1000000007
#define MO 1000000006
#define M 998244353
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
ll modExpo(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modExpo((x*x)%MOD,n/2);
    else                             //n is odd

        return (x*modExpo((x*x)%MOD,(n-1)/2))%MOD;

}
ll modInverse(ll n)
{
    return modExpo(n,MOD-2);
}
#define N 1000000
//Variables Start
ll n,m,k,ar[N],seg[4*N],lazy[4*N];
string s,s1;
//Variables End
void push(ll node)
{
    seg[node]+=lazy[node];
    lazy[2*node]+=lazy[node];
    lazy[2*node+1]+=lazy[node];
    lazy[node]=0;

}
void update(ll node,ll l,ll r,ll st,ll en,ll val)
{
    push(node);
    if(l>en||r<st)return;
    if( st<=l && r<=en)
    {
        lazy[node]+=val;
        push(node);
        return;
    }
    ll mid=(l+r)>>1;
    update(2*node,l,mid,st,en,val);
    update(2*node+1,mid+1,r,st,en,val);
    seg[node]=max(seg[2*node],seg[2*node+1]);

}
ll query(ll node,ll l,ll r)
{
    if(l>N || r<1)return -1;
    if(l==r)return l;
    push(node);
    push(2*node);
    push(2*node+1);
    ll mid=(l+r)>>1;
    if(seg[2*node+1]>0)return query(2*node+1,mid+1,r);
    if(seg[2*node]>0)return query(2*node,l,mid);
    return -1;
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
        vi a,b;
        cin>>n>>m;
        rep(i,0,n)
        {
            ll x;cin>>x;
            a.pb(x);
            update(1,1,N,1,x,1);
        }
        rep(i,0,m)
        {
            ll x;cin>>x;
            b.pb(x);
            update(1,1,N,1,x,-1);
        }
        cin>>k;
        while(k--)
        {
            ll ty,ind,val;
            cin>>ty>>ind>>val;
            ind--;
            if(ty==1)
            {
                update(1,1,N,1,a[ind],-1);
                a[ind]=val;
                update(1,1,N,1,a[ind],1);
            }
            else
            {
                update(1,1,N,1,b[ind],1);
                b[ind]=val;
                update(1,1,N,1,b[ind],-1);

            }
            cout<<query(1,1,N)<<endl;
        }
    }
    return 0;

}


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

#pragma once

const int oo = 0x3f3f3f3f;
int lim = 300000 + 10;
//int base[300000];
class node {
    public:
        node *l, *r;
        int mx, lz;

        node() : l(0), r(0), mx(0), lz(0){}

        node* le(){
            if (l == nullptr){
                l = new node();
            }
            return l;
        }

        node* ri(){
            if (r == nullptr){
                r = new node();
            }
            return r;
        }

        void push(){
            le(); ri();

            if (lz){
                l->mx += lz;
                l->lz += lz;
                r->mx += lz;
                r->lz += lz;
                lz = 0;
            }
        }

        void fix(){
            mx = max(le()->mx, ri()->mx);
        }
    };
class st{
    public:
    node *root;

    st(){
        root = new node();
    }
   int update(int x, int v){
        // cout << "[ " << x << " " << y << " " << v << endl;
        update(root, 0, lim, 1, x+1, v);
    }

    int update(node *u, int b, int e, int x, int y, int v){

        if (x <= b && e <= y){

            u->lz+= v;
            u->mx += v;
        } else {
            int m = (b + e) >> 1;

            u->push();

            if (x < m) update(u->l, b, m, x, y, v);
            if (m < y) update(u->r, m, e, x, y, v);

            u->fix();
        }

        // cout << "UPDATE:" << b << " " << e << " " << x << " " << y << " " << v << " : " << u->mx << " " << u->lz << endl;
    }
    int max_r() { return root->mx;}
    int pos_f (node *u, int b, int e){
        if (b == e-1){
            //cout<<b<<" : "<<u->mx<<endl;
            return b;
        }
        int m = (b+e)/2;
        u->push();
        if(u->ri()->mx >0){
            return pos_f(u->ri(), m,e);
        }
        return pos_f(u->le(),b,m);
    }
    int q(){
        return pos_f(root,0,lim);
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n,0);
    vector<ll> b(m,0);
    st pepe;
    for(int i =0; i < n;++i){
        cin>> a[i];
        pepe.update(a[i], 1);
    }
    for(int i =0; i < m; ++i){
        cin>>b[i];
        pepe.update(b[i],-1);
    }
    ll q;
    cin>>q;
    while(q--){
        ll t, i, x;

        cin>>t>>i>>x;
        if(t == 1){
          //cout<<"asdasd"<<endl;
           pepe.update(a[i-1], -1);
           //cout<<"ffff"<<endl;
           pepe.update(x,1);
           //cout<<"lll"<<endl;
           a[i-1] = x;
        }
        else{
            pepe.update(b[i-1], 1);
            pepe.update(x,-1);
            b[i-1] = x;
        }
        //cout<<"kk"<<endl;
        if(pepe.root->mx <= 0){
            cout<<-1<<endl;
        }
        else{
        cout<<pepe.q()<<endl;

        }
    }

    return 0;
}

/*
4 6
1 8 2 4
3 3 6 1 5 2
1
1 1 1
*/


#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

#pragma once

const int oo = 0x3f3f3f3f;
int lim = 1000000 + 10;
//int base[300000];
class node {
    public:
        node *l, *r;
        int mx, lz;

        node() : l(0), r(0), mx(0), lz(0){}

        node* le(){
            if (l == nullptr){
                l = new node();
            }
            return l;
        }

        node* ri(){
            if (r == nullptr){
                r = new node();
            }
            return r;
        }

        void push(){
            le(); ri();

            if (lz){
                l->mx += lz;
                l->lz += lz;
                r->mx += lz;
                r->lz += lz;
                lz = 0;
            }
        }

        void fix(){
            mx = max(le()->mx, ri()->mx);
        }
    };
class st{
    public:
    node *root;

    st(){
        root = new node();
    }
   int update(int x, int v){
        // cout << "[ " << x << " " << y << " " << v << endl;
        update(root, 0, lim, 1, x+1, v);
    }

    int update(node *u, int b, int e, int x, int y, int v){

        if (x <= b && e <= y){

            u->lz+= v;
            u->mx += v;
        } else {
            int m = (b + e) >> 1;

            u->push();

            if (x < m) update(u->l, b, m, x, y, v);
            if (m < y) update(u->r, m, e, x, y, v);

            u->fix();
        }

        // cout << "UPDATE:" << b << " " << e << " " << x << " " << y << " " << v << " : " << u->mx << " " << u->lz << endl;
    }
    int max_r() { return root->mx;}
    int pos_f (node *u, int b, int e){
        if (b == e-1){
            //cout<<b<<" : "<<u->mx<<endl;
            return b;
        }
        int m = (b+e)/2;
        u->push();
        if(u->ri()->mx >0){
            return pos_f(u->ri(), m,e);
        }
        return pos_f(u->le(),b,m);
    }
    int q(){
        return pos_f(root,0,lim);
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n,0);
    vector<ll> b(m,0);
    st pepe;
    for(int i =0; i < n;++i){
        cin>> a[i];
        pepe.update(a[i], 1);
    }
    for(int i =0; i < m; ++i){
        cin>>b[i];
        pepe.update(b[i],-1);
    }
    ll q;
    cin>>q;
    while(q--){
        ll t, i, x;

        cin>>t>>i>>x;
        if(t == 1){
          //cout<<"asdasd"<<endl;
           pepe.update(a[i-1], -1);
           //cout<<"ffff"<<endl;
           pepe.update(x,1);
           //cout<<"lll"<<endl;
           a[i-1] = x;
        }
        else{
            pepe.update(b[i-1], 1);
            pepe.update(x,-1);
            b[i-1] = x;
        }
        //cout<<"kk"<<endl;
        if(pepe.root->mx <= 0){
            cout<<-1<<endl;
        }
        else{
        cout<<pepe.q()<<endl;

        }
    }

    return 0;
}

/*
4 6
1 8 2 4
3 3 6 1 5 2
1
1 1 1
*/


#include<bits/stdc++.h>

using namespace std;
const int N = 2e6+100;
int tag[N<<1],maxx[N<<1];
int a[N],b[N];
void pushdown(int rt,int l,int r){
	if(tag[rt]){
		tag[rt<<1]+=tag[rt];
		tag[rt<<1|1]+=tag[rt];
		maxx[rt<<1]+=tag[rt];
		maxx[rt<<1|1]+=tag[rt];
		tag[rt]=0;
	}
}
void update(int rt,int nl,int nr,int l,int r,int x){
	if(nl<=l&&r<=nr){
		maxx[rt]+=x;
		tag[rt]+=x;
		return ;
	}
	int mid=(l+r)>>1;
	pushdown(rt,l,r);
	if(nl<=mid) update(rt<<1,nl,nr,l,mid,x);
	if(nr>mid) update(rt<<1|1,nl,nr,mid+1,r,x);
	maxx[rt]=max(maxx[rt<<1|1],maxx[rt<<1]);
}
int query(int rt,int l,int r){
	if(l==r){
		return l;
	}
	int mid=(l+r)>>1;
	pushdown(rt,l,r);
	if(maxx[rt<<1|1]>0){
		return query(rt<<1|1,mid+1,r);
	}
	return query(rt<<1,l,mid);
}
int main(){
	int n,m,q;
	scanf("%d %d",&n,&m);
	memset(maxx,0,sizeof(maxx));
	memset(tag,0,sizeof(tag));
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),update(1,1,a[i],1,2000002,1);
	for(int i=1;i<=m;i++) scanf("%d",&b[i]),update(1,1,b[i],1,2000002,-1);
	//cout<<query(1,1,2000002)<<endl;
	scanf("%d",&q);
	while(q--){
		int op,id,num;
		scanf("%d %d %d",&op,&id,&num);
		if(op==1){
			update(1,1,a[id],1,2000002,-1);
			a[id]=num;
			update(1,1,a[id],1,2000002,1);
		}
		else{
				update(1,1,b[id],1,2000002,1);
				b[id]=num;
				update(1,1,b[id],1,2000002,-1);
		}
		int ok=query(1,1,2000002);
		if(maxx[1]<=0) puts("-1");
		else printf("%d\n",ok);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
#define ll long long
#define maxn 1000110
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define lc (root<<1)
#define rc ((root<<1)|1)
const ll mod = 1e9+7;

ll a[maxn];
int L[maxn<<2],R[maxn<<2],lazy[maxn<<2];
ll kmin[maxn<<2],dx[maxn<<2];

void build(int l,int r,int root){
	if(l==r){
		kmin[root] = a[l];
		L[root] = R[root] = l;
		lazy[root] = 0;
		dx[root] = 0;
		return;
	}
	int mid = (l+r)/2;
	build(l,mid,lc);
	build(mid+1,r,rc);
	kmin[root] = min(kmin[lc],kmin[rc]);
	L[root] = l;
	R[root] = r;
	lazy[root] = 0;
	dx[root] = 0;
	return ;
}

void update(int l,int r,ll p,int root){
	if(l==L[root] && r==R[root]){
		lazy[root] = 1;
		dx[root] += p;
		kmin[root] += p;
		return ;
	}
	int Ll = L[root],Rr = R[root];
	int mid = (Ll+Rr)/2;
	if(lazy[root]){
		lazy[root] = 0;
		dx[root] = 0;
		update(Ll,mid,dx[root],lc);
		update(mid+1,Rr,dx[root],rc);
	}
	if(r<=mid){
		update(l,r,p,lc);
	}else if(l>mid){
		update(l,r,p,rc);
	}else{
		update(l,mid,p,lc);
		update(mid+1,r,p,rc);
	}
	kmin[root] = min(kmin[lc],kmin[rc]);
}

int query(int l,int r,int root=1){
	int Ll = L[root],Rr = R[root];
	int mid = (Ll+Rr)/2;
	if(l==Ll && r==Rr){
		return kmin[root];
	}
	if(lazy[root]){
		update(Ll,mid,dx[root],lc);
		update(mid+1,Rr,dx[root],rc);
		lazy[root] = 0;
		dx[root] = 0;
	}
	if(r<=mid){
		return query(l,r,lc);
	}else if(l>mid){
		return query(l,r,rc);
	}else{
		return min(query(l,mid,lc),query(mid+1,r,rc));
	}
}

int dishes[maxn];
int pupils[maxn];

int solve(){
	int l=1,r=1e6,mid;
	if(query(l,r)>=0)return -1;

	while(l<r){
		mid = (l+r+1)/2;
		if(query(mid,r)<0){
			l = mid;
		}else{
			r = mid-1;
		}
	}
	return l;
}

void disp(){
	for(int i=1;i<=10;i++){
		cout<<query(i,i)<<" ";
	}
	cout<<endl;
}
int main(){
	// freopen("1.in","r",stdin);
	// freopen("1.out","w",stdout);

	// ios::sync_with_stdio(false);
	// cin.tie(0);

	int n,m;
	while(scanf("%d%d",&n,&m)==2){
		int x;
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++){
			scanf("%d",&x);
			a[x]--;
			dishes[i] = x;
		}
		for(int i=1;i<=m;i++){
			scanf("%d",&x);
			a[x]++;
			pupils[i] = x;
		}
		for(int i=1e6+1;i>=0;i--){
			a[i] += a[i+1];
		}
		build(1,1e6+5,1);
		int q,id,index;
		scanf("%d",&q);
		int p1;

		// disp();
		for(int i=0;i<q;i++){
			scanf("%d%d%d",&id,&index,&x);
			p1 = id==1?dishes[index]:pupils[index];

			if(id==1)dishes[index] = p1;
			else pupils[index]=p1;

			if(x>p1){
				update(p1+1,x,(id==1?-1:1),1);
			}else if(x<p1){
				update(x+1,p1,(id==1?1:-1),1);
			}
			printf("%d\n",solve());
			// disp();
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
#define ll long long
#define maxn 1000110
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define lc (root<<1)
#define rc ((root<<1)|1)
const ll mod = 1e9+7;

ll a[maxn];
int L[maxn<<2],R[maxn<<2],lazy[maxn<<2];
ll kmin[maxn<<2],dx[maxn<<2];

void build(int l,int r,int root){
	if(l==r){
		kmin[root] = a[l];
		L[root] = R[root] = l;
		lazy[root] = 0;
		dx[root] = 0;
		return;
	}
	int mid = (l+r)/2;
	build(l,mid,lc);
	build(mid+1,r,rc);
	kmin[root] = min(kmin[lc],kmin[rc]);
	L[root] = l;
	R[root] = r;
	lazy[root] = 0;
	dx[root] = 0;
	return ;
}

void update(int l,int r,ll p,int root){
	if(l==L[root] && r==R[root]){
		lazy[root] = 1;
		dx[root] += p;
		kmin[root] += p;
		return ;
	}
	int Ll = L[root],Rr = R[root];
	int mid = (Ll+Rr)/2;
	if(lazy[root]){
		update(Ll,mid,dx[root],lc);
		update(mid+1,Rr,dx[root],rc);
		lazy[root] = 0;
		dx[root] = 0;
	}
	if(r<=mid){
		update(l,r,p,lc);
	}else if(l>mid){
		update(l,r,p,rc);
	}else{
		update(l,mid,p,lc);
		update(mid+1,r,p,rc);
	}
	kmin[root] = min(kmin[lc],kmin[rc]);
}

int query(int l,int r,int root=1){
	int Ll = L[root],Rr = R[root];
	int mid = (Ll+Rr)/2;
	if(l==Ll && r==Rr){
		return kmin[root];
	}
	if(lazy[root]){
		update(Ll,mid,dx[root],lc);
		update(mid+1,Rr,dx[root],rc);
		lazy[root] = 0;
		dx[root] = 0;
	}
	if(r<=mid){
		return query(l,r,lc);
	}else if(l>mid){
		return query(l,r,rc);
	}else{
		return min(query(l,mid,lc),query(mid+1,r,rc));
	}
}

int dishes[maxn];
int pupils[maxn];

int solve(){
	int l=1,r=1e6,mid;
	if(query(l,r)>=0)return -1;

	while(l<r){
		mid = (l+r+1)/2;
		if(query(mid,r)<0){
			l = mid;
		}else{
			r = mid-1;
		}
	}
	return l;
}

void disp(){
	for(int i=1;i<=10;i++){
		cout<<query(i,i)<<" ";
	}
	cout<<endl;
}

void echo(int n,int m){
	cout<<"dish:";
	for(int i=1;i<=n;i++){
		cout<<dishes[i]<<" ";
	}
	cout<<endl;
	cout<<"pupils:";
	for(int i=1;i<=m;i++){
		cout<<pupils[i]<<" ";
	}
	cout<<endl;
}
int main(){
	// freopen("1.in","r",stdin);
	// freopen("1.out","w",stdout);

	// ios::sync_with_stdio(false);
	// cin.tie(0);

	int n,m;
	while(scanf("%d%d",&n,&m)==2){
		int x;
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++){
			scanf("%d",&x);
			a[x]--;
			dishes[i] = x;
		}
		for(int i=1;i<=m;i++){
			scanf("%d",&x);
			a[x]++;
			pupils[i] = x;
		}
		for(int i=1e6+1;i>=0;i--){
			a[i] += a[i+1];
		}
		build(1,1e6+5,1);
		int q,id,index;
		scanf("%d",&q);
		int p1;

		// disp();
		// echo(n,m);
		for(int i=0;i<q;i++){
			scanf("%d%d%d",&id,&index,&x);
			p1 = id==1?dishes[index]:pupils[index];

			if(id==1)dishes[index] = x;
			else pupils[index]=x;

			if(x>p1){
				update(p1+1,x,(id==1?-1:1),1);
			}else if(x<p1){
				update(x+1,p1,(id==1?1:-1),1);
			}
			printf("%d\n",solve());
			// disp();
			// echo(n,m);
		}
	}
	return 0;
}


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

const int N = 1e6 + 5;
const int MX = 3e5 + 5;

int st[4*N] , lazy[4*N] , a[MX] , b[MX];

void push(int p , int l , int r)
{
    if(lazy[p])
    {
        st[p] += lazy[p];
        if(l != r)
        {
            lazy[2*p] += lazy[p];
            lazy[2*p+1] += lazy[p];
        }
        lazy[p] = 0;
    }
}
void update(int a , int b , int val , int l = 0 , int r = N-1 , int p = 1)
{
    push(p,l,r);
    if(b < l || r < a) return;
    if(a <= l && r <= b)
    {
        lazy[p] = val;
        push(p,l,r);
        return;
    }
    int mid = (l+r)>>1;
    update(a,b,val,l,mid,2*p);
    update(a,b,val,mid+1,r,2*p+1);
    st[p] = min(st[2*p],st[2*p+1]);
}
int query(int l = 0 , int r = N-1 , int p = 1)
{
    push(p,l,r);
    if(st[p] >= 0) return 0;
    if(l == r) return l;
    int mid = (l+r)>>1;

    int res = query(mid+1,r,2*p+1);
    if(!res) res = query(l,mid,2*p);
    return res;
}
int main()
{
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    int n , m;  cin >> n >> m;
    for(int i = 0 ;  i < n ; i++)   cin >> a[i] , update(0,a[i],-1);
    for(int i = 0 ;  i < m ; i++)   cin >> b[i] , update(0,b[i],+1);

    update(0,0,-m-1);
    int q;  cin >> q;
    while(q--)
    {
        int t , i , x;  cin >> t >> i >> x; i--;
        if(t == 1)
        {
            update(0,a[i],+1);
            a[i] = x;
            update(0,a[i],-1);
        }
        else
        {
            update(0,b[i],-1);
            b[i] = x;
            update(0,b[i],+1);
        }

        int res = query();
        if(!res) res = -1;

        cout << res << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = 3e5 + 7;
const int MAXV = 3 * MAXN;

int n, m;
int a[MAXN], b[MAXN];

int q;
int t[MAXN], p[MAXN], x[MAXN];

void read() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> b[i];
    }
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> t[i];
        if (t[i] <= 2) {
            cin >> p[i] >> x[i];
            --p[i];
        }
    }
}

int u = 0;
int v[MAXV];

void compr() {
    for (int i = 0; i < n; ++i) {
        v[u++] = a[i];
    }
    for (int i = 0; i < m; ++i) {
        v[u++] = b[i];
    }
    for (int i = 0; i < q; ++i) {
        if (t[i] <= 2) {
            v[u++] = x[i];
        }
    }
    sort(v, v + u);
    u = unique(v, v + u) - v;
    for (int i = 0; i < n; ++i) {
        a[i] = lower_bound(v, v + u, a[i]) - v;
    }
    for (int i = 0; i < m; ++i) {
        b[i] = lower_bound(v, v + u, b[i]) - v;
    }
    for (int i = 0; i < q; ++i) {
        if (t[i] <= 2) {
            x[i] = lower_bound(v, v + u, x[i]) - v;
        }
    }
}

int tree[MAXV << 2], add[MAXV << 2];

void push(int v) {
    tree[v * 2 + 1] += add[v];
    add[v * 2 + 1] += add[v];
    tree[v * 2 + 2] += add[v];
    add[v * 2 + 2] += add[v];
    add[v] = 0;
}

void upd(int v, int tl, int tr, int l, int r, int x) {
    if (tr < l || r < tl) {
        return;
    }
    if (l <= tl && tr <= r) {
        tree[v] += x;
        add[v] += x;
        return;
    }
    int tm = (tl + tr) >> 1;
    push(v);
    upd(v * 2 + 1, tl, tm, l, r, x);
    upd(v * 2 + 2, tm + 1, tr, l, r, x);
    tree[v] = max(tree[v * 2 + 1], tree[v * 2 + 2]);
}

int get(int v, int tl, int tr) {
    if (tl == tr) {
        return tl;
    }
    int tm = (tl + tr) >> 1;
    push(v);
    if (tree[v * 2 + 2] >= 1) {
        return get(v * 2 + 2, tm + 1, tr);
    }
    else {
        return get(v * 2 + 1, tl, tm);
    }
}

void add1(int x) {
    //cout << x << ' ' << 1 << '\n';
    upd(0, 0, MAXV, 0, x, 1);
}

void del1(int x) {
    //cout << x << ' ' << -1 << '\n';
    upd(0, 0, MAXV, 0, x, -1);
}

void upd1(int p, int x) {
    del1(a[p]);
    a[p] = x;
    add1(a[p]);
}

void add2(int x) {
    //cout << x << ' ' << -1 << '\n';
    upd(0, 0, MAXV, 0, x, -1);
}

void del2(int x) {
    //cout << x << ' ' << 1 << '\n';
    upd(0, 0, MAXV, 0, x, 1);
}

void upd2(int p, int x) {
    del2(b[p]);
    b[p] = x;
    add2(b[p]);
}

int get() {
    if (tree[0] >= 1) {
        return get(0, 0, MAXV);
    }
    else {
        return -1;
    }
}

void solve() {
    compr();
    for (int i = 0; i < n; ++i) {
        add1(a[i]);
    }
    for (int i = 0; i < m; ++i) {
        add2(b[i]);
    }
}

void print() {
    for (int i = 0; i < q; ++i) {
        if (t[i] == 1) {
            upd1(p[i], x[i]);
        }
        else {
            upd2(p[i], x[i]);
        }
        {
            int ans = get();
            if (ans == -1) {
                cout << "-1\n";
            }
            else {
                cout << v[ans] << '\n';
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    read();
    solve();
    print();

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef double lf;

const int N = 52+20;
const ll oo = 1e18;
const int MOD = 1e9+7;

struct st {
  st *left, *right;
  int mn, l, r, m, lazy;
  st(int l, int r) : l(l), r(r), lazy(0), mn(0) {
    m = (l + r) / 2;
    if(l != r) {
      left = new st(l, m);
      right = new st(m+1, r);
    }
  }
  void propagate() {
    if(lazy) {
      mn += lazy;
      if(l != r) left->lazy += lazy;
      if(l != r) right->lazy += lazy;
      lazy = 0;
    }
  }
  void update(int a, int b, int val) {
    propagate();
    if(a == l && b == r) {
      lazy += val;
      propagate();
    } else{
      if(b <= m) left->update(a, b, val), right->propagate();
      else if(a > m) right->update(a, b, val), left->propagate();
      else left->update(a, m, val), right->update(m+1, b, val);
      mn = min(left->mn, right->mn);
    }
  }
  int get() {
    propagate();
    if(mn >= 0) return -1;
    if(l == r) return l;
    else {
      left->propagate(); right->propagate();
      if(right->mn < 0) return right->get();
      return left->get();
    }
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #else
    #define endl '\n'
  #endif

  int n, m;
  while(cin >> n >> m) {
    st tree(1, 1e6);

    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) {
      cin >> a[i];
      tree.update(1, a[i], -1);
    }
    vector<int> b(m+1);
    for(int i = 1; i <= m; i++) {
      cin >> b[i];
      tree.update(1, b[i], 1);
    }

    int q; cin >> q;
    while(q--) {
      int cmd; cin >> cmd;
      if(cmd == 1) { /// a
        int p, x; cin >> p >> x;
        tree.update(1, a[p], 1);
        a[p] = x;
        tree.update(1, a[p], -1);
      } else { /// b
        int p, x; cin >> p >> x;
        tree.update(1, b[p], -1);
        b[p] = x;
        tree.update(1, b[p], 1);
      }
      cout << tree.get() << endl;
    }
  }
}


/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
template<class C, size_t Y> struct TP {
    void operator()(Dbg& os, const C &t) { TP<C, Y-1>()(os, t); os << ", " << get<Y-1>(t); }
};
template<class C> struct TP<C, 1> { void operator()(Dbg& os, const C &t) { os << get<0>(t); } };
template<class... C> Dbg& operator<<(const tuple<C...> &t) {
    os << '{', TP<decltype(t), sizeof...(C)>()(*this, t); return *this << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args ...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(string(#args)), args), dbg << endl
#define ASSERT(a, o, b) { if (!((a) o (b))) bug(a, b), assert((a) o (b)); }
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 300005, mxx = 1000005;

// In case you ever need l, r of update / query, keep l,r in node.t, in cmbn l = ls.l, r = rs.r, change in query functions.
struct node {   // Try to use as less segtrees as possible for cache, but maybe avoid merging unrelateds.
/*
Caution: queryIndex is combiner of all ancestors, lazy without propagation.
*/
    static const bool isLazy = 1;   // when lazy, can't use updateIndex or queryIndex.
    static constexpr ll RESET = inf;  // base value for query. For using pair t = value of RESET, not RESET;
    static constexpr ll NOLAZY = 0;

    ll t = RESET/*MUST*/, lazy = NOLAZY;    // if there is no lazy, static update's val type lazy, similar type for NOLAZY;

    void cmbn(node l, node r) { t = min(l.t, r.t);/*t.cmbn(l.t, r.t);*/ }    // l or r can be itself, so no reference

    void assignLeaf(int idx) { t = 0;/*if (idx<mxn) t = a[idx]*/; }  // check arr size

    void upd(const decltype(lazy) &val, int span) { // called from updateIndex too with span==1.
        t += val;
        if (isLazy && span>1) { /*if (lazy==NOLAZY) lazy = RESET;*/ lazy += val; }
    }
};

template <class T> class SegmentTree//{
{
    int H, N, mnIdx;

    void propagate(int at, int lspan, int rspan) {
        t[at<<1].upd(t[at].lazy, lspan), t[at<<1|1].upd(t[at].lazy, rspan), t[at].lazy = t[0].lazy;
    }

    void push(int l, int r) {
        if (!T::isLazy) return;
        int h = H, k = 1<<(H-1);
        for (l += N, r += N-1; h; h--, k >>= 1) for (int i = l>>h; i <= r>>h; i++)
            if (t[i].lazy != t[0].lazy) propagate(i, k, k);
    }

#define bacca int mid = (l+r)>>1, lson = at<<1, rson = lson|1;

    void updRng(const int &at, const int &l, const int &r, const int &ul, const int &ur, decltype(T::lazy) &val) {
        if (ul<=l && r<=ur) return t[at].upd(val, r-l+1);  // assign t[at] and/or t[at].lazy
        bacca
        if (T::isLazy && t[at].lazy!=t[0].lazy && l!=r) propagate(at, mid-l+1, r-mid);
        if (!(mid<ul)) updRng(lson, l, mid, ul, ur, val);
        if (!(mid+1>ur)) updRng(rson, mid+1, r, ul, ur, val);
        if (T::isLazy) t[at].cmbn(t[lson], t[rson]);    // assign t[at]
    }

    int srchUtil(const int &at, const int &l, const int &r, const decltype(T::t) &val) {
        if (t[at].t>val) return N+1;
        if (l==r) return l;
        bacca
        if (T::isLazy && t[at].lazy!=t[0].lazy) propagate(at, mid-l+1, r-mid);
        if (t[rson].t<=val) return srchUtil(rson, mid+1, r, val);
        else return srchUtil(lson, l, mid, val);
    }

#undef bacca

public:
    T *t;   // make vector/bitset if needed to assign/copy.
    SegmentTree(int _n, int _mnIdx = 0) : H(32-__builtin_clz(_n-1)), mnIdx(_mnIdx) {
        N = 1U<<H, t = new T[(N<<1)+3];
    }
    ~SegmentTree() { delete[] t; }

    void build() {    // call iff you can't simply set base value of query to whole t
        for (int i = N; i< (N<<1); i++) t[i].assignLeaf(i-N+mnIdx);
        for (int i = N-1; i; i--) t[i].cmbn(t[i<<1], t[i<<1|1]);
        if (T::isLazy) for (int i = 0; i < N<<1; i++) t[i].lazy = t[0].lazy;
    }

    void reset() {
        if (is_trivially_copyable<T>() and !T::RESET && !T::NOLAZY) memset(t, 0, ((N<<1)+3)*sizeof(T));
        else for (int i = 1; i < N<<1; i++) t[i] = t[0];
    }

    void updateIndex(int idx, const decltype(T::lazy) &val) { idx -= mnIdx;
        for (t[idx += N].upd(val, 1), idx >>= 1; idx>=1; idx >>= 1) t[idx].cmbn(t[idx<<1], t[idx<<1|1]);
    }

    void updateRange(int ul, int ur, decltype(T::lazy) val) { if (ul<=ur) updRng(1, 0, N-1, ul-mnIdx, ur-mnIdx, val); }

// updateRange+queryIndex is actually lazy without propagation, where t itself is lazy, this can't be used when order of
// modifications is important e.g. assign (when lazy with prop. it may have different cmbn function or no cmbn)
    decltype(T::t) queryIndex(int idx) { idx -= mnIdx;
        T ret;
        for (idx += N; idx > 0; idx >>= 1) ret.cmbn(ret, t[idx]);
        return ret.t;
    }

    decltype(T::t) queryRange(int l, int r) { l -= mnIdx, r -= mnIdx;
        r++, push(l, l+1), push(r-1, r);
        T resl, resr;
        for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
            if (l&1) resl.cmbn(resl, t[l++]);
            if (r&1) resr.cmbn(t[--r], resr);
        }
        resl.cmbn(resl, resr);
        return resl.t;
    }

    void pushAll() {
        if (T::isLazy) push(0, N);
        else for (int i = 1; i < N; ++i) t[i<<1].cmbn(t[i], t[i<<1]), t[i<<1|1].cmbn(t[i], t[i<<1|1]), t[i].t = T::RESET;
    }

// returns lower_bound if found, else return st.N+1. To find upper_bound replace 1st and 3rd line's >= by >.
    int search(decltype(T::t) val) { return srchUtil(1, 0, N-1, val)+mnIdx; }

    T& at(const int &idx) { return t[N+idx-mnIdx]; }
};//}

SegmentTree<node> st(mxx, 0); // if mnIdx doesn't match there can be corner case for search

int n, m, a[mxn], b[mxn];

signed main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.precision(11);
    cin >> n >> m;
    st.build();
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        st.updateRange(1, a[i], -1);
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        st.updateRange(1, b[i], 1);
    }
    cin >> Q;
    while (Q--) {
        int t, i, x;
        cin >> t >> i >> x;
        if (t==1) {
            st.updateRange(1, a[i], 1), a[i] = x, st.updateRange(1, a[i], -1);
        } else {
            st.updateRange(1, b[i], -1), b[i] = x, st.updateRange(1, b[i], 1);
        }
        int o = st.search(-1);
        cout << (o<mxx ? o : -1) << '\n';
    }
}


/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 300005
#define maxm 1000006
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,m,q,a[maxn],b[maxn],t[maxn << 3],lim;
pair <int,pii> qq[maxn];
vector <int> rr;
void Push(int id)
{
    if (!t[id]) return;
    t[2*id] += t[id];
    t[2*id+1] += t[id];
    t[id] = 0;
}
void Update(int l,int r,int id,int u,int v,int val)
{
    if (l > v || r < u) return;
    if (u <= l && r <= v)
    {
        t[id] += val;
        return;
    }
    Push(id);
    int mid = (l+r) >> 1;
    Update(l,mid,2*id,u,v,val);
    Update(mid+1,r,2*id+1,u,v,val);
}
int Find(int l,int r,int id)
{
    if (l == r)
    {
        if (t[id] < 0) return l;
        return 0;
    }
    Push(id);
    int mid = (l+r) >> 1;
    int x = Find(mid+1,r,2*id+1);
    if (x) return x;
    return Find(l,mid,2*id);
}
int Recode(int x)
{
    return upper_bound(rr.begin(),rr.end(),x) - rr.begin();
}
void Enter()
{
    cin >> n >> m;
    FOR(i,1,n)
    {
        cin >> a[i];
        rr.pb(a[i]);
    }
    FOR(i,1,m)
    {
        cin >> b[i];
        rr.pb(b[i]);
    }
    cin >> q;
    FOR(i,1,q)
    {
        int x,y,z;
        cin >> x >> y >> z;
        qq[i] = mp(x,mp(y,z));
        rr.pb(z);
    }
    sort(rr.begin(),rr.end());
    rr.resize(unique(rr.begin(),rr.end()) - rr.begin());
    lim = rr.size();
}
void Prepare()
{
    FOR(i,1,n)
    {
        Update(1,lim,1,1,Recode(a[i]),-1);
    }
    FOR(i,1,m)
    {
        Update(1,lim,1,1,Recode(b[i]),1);
    }
}
void Pro()
{
    FOR(i,1,q)
    {
        int type = qq[i].F,
            x = qq[i].S.F,
            y = qq[i].S.S;
        if (type & 1)
        {
            Update(1,lim,1,1,Recode(a[x]),1);
            a[x] = y;
            Update(1,lim,1,1,Recode(a[x]),-1);
        }
        else
        {
            Update(1,lim,1,1,Recode(b[x]),-1);
            b[x] = y;
            Update(1,lim,1,1,Recode(b[x]),1);
        }
        x = Find(1,lim,1);
        if (x) x = rr[x-1];
        else x = -1;
        cout << x << '\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    //freopen(Task".inp", "r",stdin);
    //freopens(Task".out", "w",stdout);
    Enter();
    Prepare();
    Pro();
    return 0;
}


/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 300005
#define maxm 1000006
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,m,q,a[maxn],b[maxn],t[maxn << 3],lz[maxn << 3],lim;
pair <int,pii> qq[maxn];
vector <int> rr;

void Push(int id)
{
    if (!lz[id]) return;
    t[2*id] += lz[id];
    t[2*id+1] += lz[id];
    lz[2*id] += lz[id];
    lz[2*id+1] += lz[id];
    lz[id] = 0;
}
void Update(int l,int r,int id,int u,int v,int val)
{
    if (l > v || r < u) return;
    if (u <= l && r <= v)
    {
        t[id] += val;
        lz[id] += val;
        return;
    }
    Push(id);
    int mid = (l+r) >> 1;
    Update(l,mid,2*id,u,v,val);
    Update(mid+1,r,2*id+1,u,v,val);
    t[id] = min(t[2*id],t[2*id+1]);
}
int Find(int l,int r,int id)
{
    if (t[id] >= 0) return 0;
    if (l == r) return l;
    Push(id);
    int mid = (l+r) >> 1;
    if (t[2*id+1] < 0) return Find(mid+1,r,2*id+1);
    return Find(l,mid,2*id);
}
int Recode(int x)
{
    return upper_bound(rr.begin(),rr.end(),x) - rr.begin();
}
void Enter()
{
    read(n),read(m);
    FOR(i,1,n)
    {
        read(a[i]);
        rr.pb(a[i]);
    }
    FOR(i,1,m)
    {
        read(b[i]);
        rr.pb(b[i]);
    }
    read(q);
    FOR(i,1,q)
    {
        int x,y,z;
        read(x),read(y),read(z);
        qq[i] = mp(x,mp(y,z));
        rr.pb(z);
    }
    sort(rr.begin(),rr.end());
    rr.resize(unique(rr.begin(),rr.end()) - rr.begin());
    lim = rr.size();
}
void Prepare()
{
    FOR(i,1,n)
    {
        Update(1,lim,1,1,Recode(a[i]),-1);
    }
    FOR(i,1,m)
    {
        Update(1,lim,1,1,Recode(b[i]),1);
    }
}
void Pro()
{
    FOR(i,1,q)
    {
        int type = qq[i].F,
            x = qq[i].S.F,
            y = qq[i].S.S;
        if (type & 1)
        {
            Update(1,lim,1,1,Recode(a[x]),1);
            a[x] = y;
            Update(1,lim,1,1,Recode(a[x]),-1);
        }
        else
        {
            Update(1,lim,1,1,Recode(b[x]),-1);
            b[x] = y;
            Update(1,lim,1,1,Recode(b[x]),1);
        }
        x = Find(1,lim,1);
        if (x) x = rr[x-1];
        else x = -1;
        writeln(x);
    }
}
int main()
{
    //ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    //freopen(Task".inp", "r",stdin);
    //freopens(Task".out", "w",stdout);
    Enter();
    Prepare();
    Pro();
    return 0;
}


/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 300005
#define maxm 1000006
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,m,q,a[maxn],b[maxn],t[maxn << 3],lim;
pair <int,pii> qq[maxn];
vector <int> rr;
void Push(int id)
{
    if (!t[id]) return;
    t[2*id] += t[id];
    t[2*id+1] += t[id];
    t[id] = 0;
}
void Update(int l,int r,int id,int u,int v,int val)
{
    if (l > v || r < u) return;
    if (u <= l && r <= v)
    {
        t[id] += val;
        return;
    }
    Push(id);
    int mid = (l+r) >> 1;
    Update(l,mid,2*id,u,v,val);
    Update(mid+1,r,2*id+1,u,v,val);
}
int Find(int l,int r,int id)
{
    if (l == r)
    {
        if (t[id] < 0) return l;
        return 0;
    }
    Push(id);
    int mid = (l+r) >> 1;
    int x = Find(mid+1,r,2*id+1);
    if (x) return x;
    return Find(l,mid,2*id);
}
int Recode(int x)
{
    return upper_bound(rr.begin(),rr.end(),x) - rr.begin();
}
void Enter()
{
    read(n),read(m);
    FOR(i,1,n)
    {
        read(a[i]);
        rr.pb(a[i]);
    }
    FOR(i,1,m)
    {
        read(b[i]);
        rr.pb(b[i]);
    }
    read(q);
    FOR(i,1,q)
    {
        int x,y,z;
        read(x),read(y),read(z);
        qq[i] = mp(x,mp(y,z));
        rr.pb(z);
    }
    sort(rr.begin(),rr.end());
    rr.resize(unique(rr.begin(),rr.end()) - rr.begin());
    lim = rr.size();
}
void Prepare()
{
    FOR(i,1,n)
    {
        Update(1,lim,1,1,Recode(a[i]),-1);
    }
    FOR(i,1,m)
    {
        Update(1,lim,1,1,Recode(b[i]),1);
    }
}
void Pro()
{
    FOR(i,1,q)
    {
        int type = qq[i].F,
            x = qq[i].S.F,
            y = qq[i].S.S;
        if (type & 1)
        {
            Update(1,lim,1,1,Recode(a[x]),1);
            a[x] = y;
            Update(1,lim,1,1,Recode(a[x]),-1);
        }
        else
        {
            Update(1,lim,1,1,Recode(b[x]),-1);
            b[x] = y;
            Update(1,lim,1,1,Recode(b[x]),1);
        }
        x = Find(1,lim,1);
        if (x) x = rr[x-1];
        else x = -1;
        writeln(x);
    }
}
int main()
{
    //ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    //freopen(Task".inp", "r",stdin);
    //freopens(Task".out", "w",stdout);
    Enter();
    Prepare();
    Pro();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;

struct SegmentTree {
    struct Node {
        int l, r, ret, laz;

        bool inside(int x, int y) {
            return x <= l && r <= y;
        }
    } a[N * 4];

    void SetRange(int l, int r, int id = 1) {
        a[id].l = l; a[id].r = r;
        a[id].ret = a[id].laz = 0;
        if (l == r)
            return;
        int mid = l + r >> 1;
        SetRange(l, mid, id << 1); SetRange(mid + 1, r, id << 1 | 1);
    }

    void Uplaz(int id) {
        a[id].ret += a[id].laz;
        if (a[id].l == a[id].r) {
            a[id].laz = 0;
            return;
        }
        a[id << 1].laz += a[id].laz;
        a[id << 1 | 1].laz += a[id].laz;
        a[id].laz = 0;
    }

    void Update(int l, int r, int val, int id = 1) {
        Uplaz(id);
        if (a[id].r < l || r < a[id].l)
            return;
        if (a[id].inside(l, r)) {
            a[id].laz += val;
            Uplaz(id);
            return;
        }
        Update(l, r, val, id << 1); Update(l, r, val, id << 1 | 1);
        a[id].ret = min(a[id << 1].ret, a[id << 1 | 1].ret);
    }

    int Query() {
        Uplaz(1);
        int curid = 1;
        while (a[curid].l != a[curid].r) {
            Uplaz(curid << 1); Uplaz(curid << 1 | 1);
            if (a[curid << 1 | 1].ret < 0)
                curid = curid << 1 | 1;
            else
                if (a[curid << 1].ret < 0)
                    curid = curid << 1;
                else return -1;
        }
        return a[curid].l;
    }
} ST;

int n, m, q;
int a[N], b[N];

int main() {
    if (fopen("exam.inp", "r"))
        freopen("exam.inp", "r", stdin),
        freopen("exam.out", "w", stdout);

    ST.SetRange(1, N - 10);

    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]),
        ST.Update(1, a[i], -1);
    for (int i = 1; i <= m; i++)
        scanf("%d", &b[i]),
        ST.Update(1, b[i], 1);

    scanf("%d", &q);
    while (q--) {
        int type, id, val;
        scanf("%d%d%d", &type, &id, &val);
        if (type == 1) {
            ST.Update(1, a[id], 1);
            a[id] = val;
            ST.Update(1, a[id], -1);
        } else {
            ST.Update(1, b[id], -1);
            b[id] = val;
            ST.Update(1, b[id], 1);
        }
        printf("%d\n", ST.Query());
    }
    //cout << ST.Query();
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x <<endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define NMAX 1000111
#define VMAX 450
#define DEBUG 0
typedef struct node {
    int left,right;
    int sum,smin;
} node;
int n,m;
node c[NMAX*4];
int a[NMAX], b[NMAX];
int q;
int values[NMAX];
void input() {
    scanf("%d%d",&n,&m);
    int number;
    for(int i=1; i<=n; i++) {
        scanf("%d",&number);
        a[i]= number;
    }
    for(int i=1; i<=m; i++) {
        scanf("%d", &number);
        b[i]= number;
    }
    //PR(a,1,n);
    //PR(b,1,m);
}
void update(int id) {
    c[id].smin = min(c[id*2].smin+ c[id*2+1].sum, c[id*2+1].smin);
    c[id].sum= c[id*2].sum + c[id*2+1].sum;
}
void build(int id,int left,int right) {
    if (left>right)
        return;
    c[id].left=left;
    c[id].right= right;
    if (left==right) {
        c[id].sum = values[left];
        c[id].smin = values[left];
        return;
    }
    int mid = (left+right)/2;
    build(id*2,left,mid);
    build(id*2+1,mid+1,right);
    update(id);
}
void init() {
    for(int i=1; i<=VMAX; i++) {
        values[i]=0;
    }
    for(int i=1; i<=n; i++) {
        values[a[i]]--;
    }
    for(int i=1; i<=m; i++) {
        values[b[i]]++;
    }
    build(1,1,VMAX);
}
void query(int id, int index, int add) {
    //cout<<"query: "<<id<<" "<<index<<" "<<add<<" ("<<c[id].left<<","<<c[id].right<<")"<<endl;
    if ((index<c[id].left)||(index>c[id].right))
        return;
    //cout<<"---"<<"("<<c[id].left<<","<<c[id].right<<") = "<<c[id].smin<<endl;
    if (c[id].left== c[id].right) {
        values[index]+=add;
        c[id].sum= values[index];
        c[id].smin= values[index];
        //cout<<"+++"<<"("<<c[id].left<<","<<c[id].right<<") = "<<c[id].smin<<endl;
        return;
    }
    query(id*2+1,index,add);
    query(id*2,index,add);
    update(id);
    //cout<<"+++"<<"("<<c[id].left<<","<<c[id].right<<") = "<<c[id].smin<<endl;
}
int getMax(int id, int sum) {
    if (c[id].left==c[id].right) {
        return c[id].left;
    }
    if ((c[id*2+1].smin+ sum)<0) {
        return getMax(id*2+1,sum);
    }
    return getMax(id*2,sum+c[id*2+1].sum);
}
void solve() {
    scanf("%d",&q);
    int type,index,v;
    for(int i=1; i<=q; i++) {
        scanf("%d%d%d",&type,&index,&v);
        //cout<<"..................."<<endl;
        //BUG(type);
        //BUG(id);
        //BUG(v);
        if(type==1) {
            //BUG(type);
            query(1,a[index],1);
            a[index]=v;
            query(1,a[index],-1);
        } else {
            //BUG(type);
            query(1,b[index],-1);
            b[index]=v;
            query(1,b[index],1);
        }
        if(c[1].smin>=0) {
            //BUG(c[1].smin);
            cout<<"-1"<<endl;
        } else {
            cout<<getMax(1,0)<<endl;
        }
    }
}
int main() {
    if (DEBUG==1) {
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    input();
    init();
    solve();
    // coding continue
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)
#define mp(x,y) make_pair((int)x,(int)y)
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define BUG(x) {cout << #x << " = " << x <<endl;}
#define PR(x,a,b) {cout << #x << " = "; FOR(i,a,b) cout << x[i] << ' '; cout << endl;}
#define ll long long
#define NMAX 1000111
#define VMAX 1000000
#define DEBUG 0
typedef struct node {
    int left,right;
    int sum,smin;
} node;
int n,m;
node c[NMAX*4];
int a[NMAX], b[NMAX];
int q;
int values[NMAX];
void input() {
    scanf("%d%d",&n,&m);
    int number;
    for(int i=1; i<=n; i++) {
        scanf("%d",&number);
        a[i]= number;
    }
    for(int i=1; i<=m; i++) {
        scanf("%d", &number);
        b[i]= number;
    }
    //PR(a,1,n);
    //PR(b,1,m);
}
void update(int id) {
    c[id].smin = min(c[id*2].smin+ c[id*2+1].sum, c[id*2+1].smin);
    c[id].sum= c[id*2].sum + c[id*2+1].sum;
}
void build(int id,int left,int right) {
    if (left>right)
        return;
    c[id].left=left;
    c[id].right= right;
    if (left==right) {
        c[id].sum = values[left];
        c[id].smin = values[left];
        return;
    }
    int mid = (left+right)/2;
    build(id*2,left,mid);
    build(id*2+1,mid+1,right);
    update(id);
}
void init() {
    for(int i=1; i<=VMAX; i++) {
        values[i]=0;
    }
    for(int i=1; i<=n; i++) {
        values[a[i]]--;
    }
    for(int i=1; i<=m; i++) {
        values[b[i]]++;
    }
    build(1,1,VMAX);
}
void query(int id, int index, int add) {
    //cout<<"query: "<<id<<" "<<index<<" "<<add<<" ("<<c[id].left<<","<<c[id].right<<")"<<endl;
    if ((index<c[id].left)||(index>c[id].right))
        return;
    //cout<<"---"<<"("<<c[id].left<<","<<c[id].right<<") = "<<c[id].smin<<endl;
    if (c[id].left== c[id].right) {
        values[index]+=add;
        c[id].sum= values[index];
        c[id].smin= values[index];
        //cout<<"+++"<<"("<<c[id].left<<","<<c[id].right<<") = "<<c[id].smin<<endl;
        return;
    }
    query(id*2+1,index,add);
    query(id*2,index,add);
    update(id);
    //cout<<"+++"<<"("<<c[id].left<<","<<c[id].right<<") = "<<c[id].smin<<endl;
}
int getMax(int id, int sum) {
    if (c[id].left==c[id].right) {
        return c[id].left;
    }
    if ((c[id*2+1].smin+ sum)<0) {
        return getMax(id*2+1,sum);
    }
    return getMax(id*2,sum+c[id*2+1].sum);
}
void solve() {
    scanf("%d",&q);
    int type,index,v;
    for(int i=1; i<=q; i++) {
        scanf("%d%d%d",&type,&index,&v);
        //cout<<"..................."<<endl;
        //BUG(type);
        //BUG(id);
        //BUG(v);
        if(type==1) {
            //BUG(type);
            query(1,a[index],1);
            a[index]=v;
            query(1,a[index],-1);
        } else {
            //BUG(type);
            query(1,b[index],-1);
            b[index]=v;
            query(1,b[index],1);
        }
        if(c[1].smin>=0) {
            //BUG(c[1].smin);
            cout<<"-1"<<endl;
        } else {
            cout<<getMax(1,0)<<endl;
        }
    }
}
int main() {
    if (DEBUG==1) {
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    }
    input();
    init();
    solve();
    // coding continue
}


//Rohit Rana
#include <bits/stdc++.h>

using namespace std;

#define int long long

#undef _GLIBCXX_DEBUG

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int MAXN = 3e5 + 7;
const int MAXV = 3 * MAXN;

int n, m;
int a[MAXN], b[MAXN];

int q;
int t[MAXN], p[MAXN], x[MAXN];

void read() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> b[i];
    }
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> t[i];
        if (t[i] <= 2) {
            cin >> p[i] >> x[i];
            --p[i];
        }
    }
}

int u = 0;
int v[MAXV];

void compr() {
    for (int i = 0; i < n; ++i) {
        v[u++] = a[i];
    }
    for (int i = 0; i < m; ++i) {
        v[u++] = b[i];
    }
    for (int i = 0; i < q; ++i) {
        if (t[i] <= 2) {
            v[u++] = x[i];
        }
    }
    sort(v, v + u);
    u = unique(v, v + u) - v;
    debug(u);
    for(int i=0;i<20;i++)
    debug(v[i]);
    for (int i = 0; i < n; ++i) {
        a[i] = lower_bound(v, v + u, a[i]) - v;
        debug(a[i]);
    }

    for (int i = 0; i < m; ++i) {
        b[i] = lower_bound(v, v + u, b[i]) - v;
        debug(b[i]);
    }
    for (int i = 0; i < q; ++i) {
        if (t[i] <= 2) {
            x[i] = lower_bound(v, v + u, x[i]) - v;
            debug(x[i]);
        }
    }
}

int tree[MAXV << 2], add[MAXV << 2];

void push(int v) {
    tree[v * 2 + 1] += add[v];
    add[v * 2 + 1] += add[v];
    tree[v * 2 + 2] += add[v];
    add[v * 2 + 2] += add[v];
    add[v] = 0;
}

void upd(int v, int tl, int tr, int l, int r, int x) {
    if (tr < l || r < tl) {
        return;
    }
    if (l <= tl && tr <= r) {
        tree[v] += x;
        add[v] += x;
        return;
    }
    int tm = (tl + tr) >> 1;
    push(v);
    upd(v * 2 + 1, tl, tm, l, r, x);
    upd(v * 2 + 2, tm + 1, tr, l, r, x);
    tree[v] = max(tree[v * 2 + 1], tree[v * 2 + 2]);
}

int get(int v, int tl, int tr) {
    if (tl == tr) {
        return tl;
    }
    int tm = (tl + tr) >> 1;
    push(v);
    if (tree[v * 2 + 2] >= 1) {
        return get(v * 2 + 2, tm + 1, tr);
    }
    else {
        return get(v * 2 + 1, tl, tm);
    }
}

void add1(int x) {
    //cout << x << ' ' << 1 << '\n';
    upd(0, 0, MAXV, 0, x, 1);
}

void del1(int x) {
    //cout << x << ' ' << -1 << '\n';
    upd(0, 0, MAXV, 0, x, -1);
}

void upd1(int p, int x) {
    del1(a[p]);
    a[p] = x;
    add1(a[p]);
}

void add2(int x) {
    //cout << x << ' ' << -1 << '\n';
    upd(0, 0, MAXV, 0, x, -1);
}

void del2(int x) {
    //cout << x << ' ' << 1 << '\n';
    upd(0, 0, MAXV, 0, x, 1);
}

void upd2(int p, int x) {
    del2(b[p]);
    b[p] = x;
    add2(b[p]);
}

int get() {
    if (tree[0] >= 1) {
        return get(0, 0, MAXV);
    }
    else {
        return -1;
    }
}

void solve() {
    compr();
    for(int i=0;i<40;i++)
    debug(tree[i]);
    for(int i=0;i<40;i++)
    debug(add[i]);
    for (int i = 0; i < n; ++i) {
        add1(a[i]);
        for(int i=0;i<40;i++)
        debug(tree[i]);
        for(int i=0;i<40;i++)
        debug(add[i]);
    }
    for (int i = 0; i < m; ++i) {
        add2(b[i]);
        for(int i=0;i<40;i++)
        debug(tree[i]);
        for(int i=0;i<40;i++)
        debug(add[i]);
    }
}

void print() {
    for (int i = 0; i < q; ++i) {
        if (t[i] == 1) {
            upd1(p[i], x[i]);
        }
        else {
            upd2(p[i], x[i]);
        }
        {
            int ans = get();
            if (ans == -1) {
                cout << "-1\n";
            }
            else {
                cout << v[ans] << '\n';
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
    read();
    solve();
    print();

    return 0;
}