#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+7;
ll tree[6*N];
ll lazy[6*N];
ll cnt[6*N];

void build(int st, int ed, int nodes)
{
    if(st == ed)
    {
        tree[nodes] = cnt[st];
        return ;
    }

    build(st, (st+ed)/2, 2*nodes);
    build((st+ed)/2 + 1, ed, 2*nodes+1);

    tree[nodes] = max(tree[2*nodes], tree[2*nodes + 1]);
}

void update(int st, int ed, int l, int r, int nodes, int val)
{
    if(lazy[nodes]!=0)
    {
        tree[nodes] += lazy[nodes];
        if(st!=ed)
        {
            lazy[2*nodes] += lazy[nodes];
            lazy[2*nodes+1] += lazy[nodes];
        }
        lazy[nodes] = 0;
    }

    if(st>r || l>ed)
        return ;

    if(st>=l && r>=ed)
    {
        tree[nodes]+=val;
        if(st!=ed)
        {
            lazy[2*nodes] += val;
            lazy[2*nodes+1] += val;
        }
        return ;
    }

    update(st, (st+ed)/2, l, r, 2*nodes, val);
    update((st+ed)/2+1, ed, l, r, 2*nodes+1, val);
    tree[nodes] = max(tree[2*nodes], tree[2*nodes+1]);
}

void push(int st, int ed, int nodes)
{
    if(lazy[nodes]!=0)
    {
        tree[nodes] += lazy[nodes];
        if(st!=ed)
        {
            lazy[2*nodes] += lazy[nodes];
            lazy[2*nodes+1] += lazy[nodes];
        }
        lazy[nodes] = 0;
    }
}

ll query(int st, int ed, int nodes)
{
    push(st, ed, nodes);

    if(st==ed)
    {
        if(tree[nodes]>0) return st;
        else return -1;
    }

    push((st+ed)/2 + 1, ed, 2*nodes + 1);

    if(tree[2*nodes+1]>0)
        return query((st+ed)/2 + 1, ed, 2*nodes+1);
    else
        return query(st, (st+ed)/2, 2*nodes);
}

int main()
{
    int t = 1;
    while(t--)
    {
        ll n, m;
        cin>>n>>m;
        ll a[n+1], b[m+1];
        int maxi = INT_MIN;

        for(int i = 1;i<=n;i++)
        {
            ll x;
            cin>>x;
            a[i] = x;
            cnt[x]++;
            maxi = max(maxi, (int)x);
        }

        for(int i=1;i<=m;i++)
        {
            ll x;
            cin>>x;
            b[i] = x;
            cnt[x]--;
            maxi = max(maxi, (int)x);
        }

        //maxi++;
        maxi = N;
        for(int i = maxi;i>=1;i--)
            cnt[i]+=cnt[i+1];

        //for(int i=1;i<=maxi;i++)
          //  cout<<cnt[i]<<" ";
        //cout<<endl;

        build(1, maxi, 1);
        ll q;
        cin>>q;

        while(q--)
        {
            ll f;
            cin>>f;

            if(f==1)
            {
                ll id, x;
                cin>>id>>x;
                update(1, maxi, 1, a[id], 1, -1);
                a[id] = x;
                update(1, maxi, 1, a[id], 1, 1);
                //for(int i=1;i<=18 ;i++)
                  //  cout<<tree[i]<<" ";
                //cout<<endl;

            }
            else
            {
                ll id, x;
                cin>>id>>x;
                update(1, maxi, 1, b[id], 1, 1);
                b[id] = x;
                update(1, maxi, 1, b[id], 1, -1);

            }
            cout<<query(1, maxi, 1)<<"\n";
        }
    }
}


#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;
typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;

struct tree {
    struct node {
        int mn = 0, push = 0;
    };

    int tl, tr, v;
    vector <node> t;

    void init(int n) {
        tl = 1;
        tr = n;
        v = 1;

        t.resize(8 * n);
    }

    void Push(int v) {
        if (!t[v].push) {
            return;
        }

        t[v].mn += t[v].push;

        t[v * 2].push += t[v].push;
        t[v * 2 + 1].push += t[v].push;

        t[v].push = 0;
    }

    void add(int v) {
        if (true) {
            Push(v);
            Push(v * 2);
            Push(v * 2 + 1);
        }
    }

    void modify(int v, int tl, int tr, int l, int r, int val) {
        add(v);
        if (l > r) {
            return;
        }

        if (tl == l && tr == r) {
            t[v].push += val;
            add(v);
        }
        else {
            int tm = (tl + tr) / 2;

            modify(v * 2, tl, tm, l, min(r, tm), val);
            modify(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);

            t[v].mn = min(t[v * 2].mn, t[v * 2 + 1].mn);
        }
    }

    void modify(int l, int r, int val) {
        modify(v, tl, tr, l, r, val);
    }

    int get(int v, int tl, int tr) {
        add(v);

        if (tl == tr) {
            return (t[v].mn < 0 ? tl : -1);
        }

        int tm = (tl + tr) / 2;
        if (t[v * 2 + 1].mn < 0) {
            return get(v * 2 + 1, tm + 1, tr);
        }
        else {
            return get(v * 2, tl, tm);
        }
    }

    int get() {
        return get(v, tl, tr);
    }
};

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

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

    vector <int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector <int> b(m + 1);
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }

    tree osu;
    osu.init(N);

    for(int i = 1; i <= n; i++) {
        osu.modify(1, a[i], -1);
    }

    for(int i = 1; i <= m; i++) {
        osu.modify(1, b[i], 1);
    }

    int q;
    cin >> q;

    while(q--) {
        int type;
        cin >> type;

        if (type == 1) {
            int i, x;
            cin >> i >> x;

            osu.modify(1, a[i], 1);
            osu.modify(1, x, -1);

            a[i] = x;
        }
        else {
            int i, x;
            cin >> i >> x;

            osu.modify(1, b[i], -1);
            osu.modify(1, x, 1);

            b[i] = x;
        }

        cout << osu.get() << "\n";
    }

    return 0;
}

/*
*/


#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;
typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;

struct tree {
    struct node {
        int mn = 0, push = 0;
    };

    int tl, tr, v;
    vector <node> t;

    void init(int n) {
        tl = 1;
        tr = n;
        v = 1;

        t.resize(12 * n);
    }

    void Push(int v) {
        t[v].mn += t[v].push;

        t[v * 2].push += t[v].push;
        t[v * 2 + 1].push += t[v].push;

        t[v].push = 0;
    }

    void add(int v) {
        if (true) {
            Push(v);
            Push(v * 2);
            Push(v * 2 + 1);
        }
    }

    void modify(int v, int tl, int tr, int l, int r, int val) {
        add(v);
        if (l > r) {
            return;
        }

        if (tl == l && tr == r) {
            t[v].push += val;
            add(v);
        }
        else {
            int tm = (tl + tr) / 2;

            modify(v * 2, tl, tm, l, min(r, tm), val);
            modify(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);

            t[v].mn = min(t[v * 2].mn, t[v * 2 + 1].mn);
        }
    }

    void modify(int l, int r, int val) {
        modify(v, tl, tr, l, r, val);
    }

    int get(int v, int tl, int tr) {
        add(v);

        if (tl == tr) {
            return (t[v].mn < 0 ? tl : -1);
        }

        int tm = (tl + tr) / 2;
        if (t[v * 2 + 1].mn < 0) {
            return get(v * 2 + 1, tm + 1, tr);
        }
        else {
            return get(v * 2, tl, tm);
        }
    }

    int get() {
        return get(v, tl, tr);
    }
};

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

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

    vector <int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector <int> b(m + 1);
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }

    tree osu;
    osu.init(N);

    for(int i = 1; i <= n; i++) {
        osu.modify(1, a[i], -1);
    }

    for(int i = 1; i <= m; i++) {
        osu.modify(1, b[i], 1);
    }

    int q;
    cin >> q;

    while(q--) {
        int type;
        cin >> type;

        if (type == 1) {
            int i, x;
            cin >> i >> x;

            osu.modify(1, a[i], 1);
            osu.modify(1, x, -1);

            a[i] = x;
        }
        else {
            int i, x;
            cin >> i >> x;

            osu.modify(1, b[i], -1);
            osu.modify(1, x, 1);

            b[i] = x;
        }

        cout << osu.get() << "\n";
    }

    return 0;
}

/*
*/


#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;
typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;

struct tree {
    struct node {
        int mn = 0, push = 0;
    };

    int tl, tr, v;
    vector <node> t;

    void init(int n) {
        tl = 1;
        tr = n;
        v = 1;

        t.resize(4 * N);
    }

    void add(int v) {
        if (t[v].push) {
            t[v * 2].push += t[v].push;
            t[v * 2 + 1].push += t[v].push;

            t[v].mn += t[v].push;
            t[v * 2].mn += t[v * 2].push;
            t[v * 2 + 1].mn += t[v * 2 + 1].push;
            t[v].push = 0;
        }
    }

    void modify(int v, int tl, int tr, int l, int r, int val) {
        add(v);
        if (l > r) {
            return;
        }

        if (tl == l && tr == r) {
            t[v].push += val;
            add(v);
        }
        else {
            int tm = (tl + tr) / 2;

            modify(v * 2, tl, tm, l, min(r, tm), val);
            modify(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);

            t[v].mn = min(t[v * 2].mn, t[v * 2 + 1].mn);
        }
    }

    void modify(int l, int r, int val) {
        modify(v, tl, tr, l, r, val);
    }

    int get(int v, int tl, int tr) {
        add(v);

        if (tl == tr) {
            return (t[v].mn < 0 ? tl : -1);
        }

        int tm = (tl + tr) / 2;
        if (t[v * 2 + 1].mn < 0) {
            return get(v * 2 + 1, tm + 1, tr);
        }
        else {
            return get(v * 2, tl, tm);
        }
    }

    int get() {
        return get(v, tl, tr);
    }
};

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

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

    vector <int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector <int> b(m + 1);
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }

    tree osu;
    osu.init(N);

    for(int i = 1; i <= n; i++) {
        osu.modify(1, a[i], -1);
    }

    for(int i = 1; i <= m; i++) {
        osu.modify(1, b[i], 1);
    }

    int q;
    cin >> q;

    while(q--) {
        int type;
        cin >> type;

        if (type == 1) {
            int i, x;
            cin >> i >> x;

            osu.modify(1, a[i], 1);
            osu.modify(1, x, -1);

            a[i] = x;
        }
        else {
            int i, x;
            cin >> i >> x;

            osu.modify(1, b[i], -1);
            osu.modify(1, x, 1);

            b[i] = x;
        }

        cout << osu.get() << "\n";
    }

    return 0;
}

/*
*/


#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;
typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;

struct tree {
    struct node {
        int mn = 0, push = 0;
    };

    int tl, tr, v;
    vector <node> t;

    void init(int n) {
        tl = 1;
        tr = n;
        v = 1;

        t.resize(4 * N);
    }

    void add(int v) {
        if (t[v].push) {
            t[v * 2].push += t[v].push;
            t[v * 2 + 1].push += t[v].push;

            t[v].mn += t[v].push;
            t[v * 2].mn += t[v].push;
            t[v * 2 + 1].mn += t[v].push;
            t[v].push = 0;
        }
    }

    void modify(int v, int tl, int tr, int l, int r, int val) {
        add(v);
        if (l > r) {
            return;
        }

        if (tl == l && tr == r) {
            t[v].push += val;
            add(v);
        }
        else {
            int tm = (tl + tr) / 2;

            modify(v * 2, tl, tm, l, min(r, tm), val);
            modify(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);

            t[v].mn = min(t[v * 2].mn, t[v * 2 + 1].mn);
        }
    }

    void modify(int l, int r, int val) {
        modify(v, tl, tr, l, r, val);
    }

    int get(int v, int tl, int tr) {
        add(v);

        if (tl == tr) {
            return (t[v].mn < 0 ? tl : -1);
        }

        int tm = (tl + tr) / 2;
        if (t[v * 2 + 1].mn < 0) {
            return get(v * 2 + 1, tm + 1, tr);
        }
        else {
            return get(v * 2, tl, tm);
        }
    }

    int get() {
        return get(v, tl, tr);
    }
};

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

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

    vector <int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector <int> b(m + 1);
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }

    tree osu;
    osu.init(N);

    for(int i = 1; i <= n; i++) {
        osu.modify(1, a[i], -1);
    }

    for(int i = 1; i <= m; i++) {
        osu.modify(1, b[i], 1);
    }

    int q;
    cin >> q;

    while(q--) {
        int type;
        cin >> type;

        if (type == 1) {
            int i, x;
            cin >> i >> x;

            osu.modify(1, a[i], 1);
            osu.modify(1, x, -1);

            a[i] = x;
        }
        else {
            int i, x;
            cin >> i >> x;

            osu.modify(1, b[i], -1);
            osu.modify(1, x, 1);

            b[i] = x;
        }

        cout << osu.get() << "\n";
    }

    return 0;
}

/*
*/


#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;
typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;

struct tree {
    struct node {
        int mn = 0, push = 0;
    };

    int tl, tr, v;
    vector <node> t;

    void init(int n) {
        tl = 1;
        tr = n;
        v = 1;

        t.resize(6 * n);
    }

    void Push(int v) {
        t[v].mn += t[v].push;

        t[v * 2].push += t[v].push;
        t[v * 2 + 1].push += t[v].push;

        t[v].push = 0;
    }

    void add(int v) {
        if (true) {
            Push(v);
            Push(v * 2);
            Push(v * 2 + 1);
        }
    }

    void modify(int v, int tl, int tr, int l, int r, int val) {
        add(v);
        if (l > r) {
            return;
        }

        if (tl == l && tr == r) {
            t[v].push += val;
            add(v);
        }
        else {
            int tm = (tl + tr) / 2;

            modify(v * 2, tl, tm, l, min(r, tm), val);
            modify(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);

            t[v].mn = min(t[v * 2].mn, t[v * 2 + 1].mn);
        }
    }

    void modify(int l, int r, int val) {
        modify(v, tl, tr, l, r, val);
    }

    int get(int v, int tl, int tr) {
        add(v);

        if (tl == tr) {
            return (t[v].mn < 0 ? tl : -1);
        }

        int tm = (tl + tr) / 2;
        if (t[v * 2 + 1].mn < 0) {
            return get(v * 2 + 1, tm + 1, tr);
        }
        else {
            return get(v * 2, tl, tm);
        }
    }

    int get() {
        return get(v, tl, tr);
    }
};

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

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

    vector <int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector <int> b(m + 1);
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }

    tree osu;
    osu.init(N);

    for(int i = 1; i <= n; i++) {
        osu.modify(1, a[i], -1);
    }

    for(int i = 1; i <= m; i++) {
        osu.modify(1, b[i], 1);
    }

    int q;
    cin >> q;

    while(q--) {
        int type;
        cin >> type;

        if (type == 1) {
            int i, x;
            cin >> i >> x;

            osu.modify(1, a[i], 1);
            osu.modify(1, x, -1);

            a[i] = x;
        }
        else {
            int i, x;
            cin >> i >> x;

            osu.modify(1, b[i], -1);
            osu.modify(1, x, 1);

            b[i] = x;
        }

        cout << osu.get() << "\n";
    }

    return 0;
}

/*
*/


#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,string>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 1000000

struct Data{
   int op,cl;
   Data(int _op,int _cl){
      op=_op;
      cl=_cl;
   }
   Data() {}
}tree[4*N];

int ar[N+5],br[N+5];

Data Merge(Data l,Data r){
   Data res;
   if(l.op>=r.cl){
      res.cl=l.cl;
      res.op=l.op+r.op-r.cl;
   }
   else{
      res.op=r.op;
      res.cl=r.cl+l.cl-l.op;
   }
   return res;
}

void update(int node,int b,int e,int idx,Data d){
   if(idx>e||idx<b) return ;
   if(b==e){
      tree[node].op+=d.op;
      tree[node].cl+=d.cl;
      if(tree[node].op>=tree[node].cl){
         tree[node].op-=tree[node].cl;
         tree[node].cl=0;
      }
      else{
         tree[node].cl-=tree[node].op;
         tree[node].op=0;
      }
      return ;
   }
   int mid=(b+e)/2;
   update(2*node,b,mid,idx,d);
   update(2*node+1,mid+1,e,idx,d);
   tree[node]=Merge(tree[2*node],tree[2*node+1]);
}

int query(int node,int b,int e,int open){
   if(b==e) return b;
   int mid=(b+e)/2;
   if(tree[2*node+1].op>open) return query(2*node+1,mid+1,e,open);
   else return query(2*node,b,mid,open+tree[2*node+1].cl-tree[2*node+1].op);
}

int main ()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m;
   cin>>n>>m;
   for(int i=1;i<=n;i++){
      cin>>ar[i];
      update(1,1,N,ar[i],Data(1,0));
   }
   for(int i=1;i<=m;i++){
      cin>>br[i];
      update(1,1,N,br[i],Data(0,1));
   }
   int q;cin>>q;
   while(q--){
      int id,idx,val;
      cin>>id>>idx>>val;
      if(id==1){
         update(1,1,N,ar[idx],Data(-1,0));
         ar[idx]=val;
         update(1,1,N,ar[idx],Data(1,0));
      }
      else{
         update(1,1,N,br[idx],Data(0,-1));
         br[idx]=val;
         update(1,1,N,br[idx],Data(0,1));
      }
      if(tree[1].op==0) cout<<-1<<"\n";
      else cout<<query(1,1,N,0)<<"\n";
   }
   return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,string>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 1000000

struct Data{
   int op,cl;
   Data(int _op,int _cl){
      op=_op;
      cl=_cl;
   }
   Data() {}
}tree[4*N];

int ar[N+5],br[N+5];

Data Merge(Data l,Data r){
   Data res;
   if(l.op>=r.cl){
      res.cl=l.cl;
      res.op=l.op+r.op-r.cl;
   }
   else{
      res.op=r.op;
      res.cl=r.cl+l.cl-l.op;
   }
   return res;
}

void update(int node,int b,int e,int idx,Data d){
   if(idx>e||idx<b) return ;
   if(b==e){
      tree[node].op+=d.op;
      tree[node].cl+=d.cl;
      if(tree[node].op>=tree[node].cl){
         tree[node].op-=tree[node].cl;
         tree[node].cl=0;
      }
      else{
         tree[node].cl-=tree[node].op;
         tree[node].op=0;
      }
      return ;
   }
   int mid=(b+e)/2;
   update(2*node,b,mid,idx,d);
   update(2*node+1,mid+1,e,idx,d);
   tree[node]=Merge(tree[2*node],tree[2*node+1]);
}

int query(int node,int b,int e,int open){
   if(b==e) return b;
   int mid=(b+e)/2;
   if(tree[2*node+1].op>open) return query(2*node+1,mid+1,e,open);
   else return query(2*node,b,mid,open+tree[2*node+1].cl-tree[2*node+1].op);
}

int main ()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m;
   cin>>n>>m;
   for(int i=1;i<=n;i++){
      cin>>ar[i];
      update(1,1,N,ar[i],Data(1,0));
   }
   for(int i=1;i<=m;i++){
      cin>>br[i];
      update(1,1,N,br[i],Data(0,1));
   }
   int q;cin>>q;
   while(q--){
      int id,idx,val;
      cin>>id>>idx>>val;
      if(id==1){
         update(1,1,N,ar[idx],Data(-1,0));
         ar[idx]=val;
         update(1,1,N,ar[idx],Data(1,0));
      }
      else{
         update(1,1,N,br[idx],Data(0,-1));
         br[idx]=val;
         update(1,1,N,br[idx],Data(0,1));
      }
      if(tree[1].op==0) cout<<-1<<endl;
      else cout<<query(1,1,N,0)<<endl;
   }
   return 0;
}


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

namespace ProconLib{

    template<class MUStruct>
    class LazySegmentTree{
        public:
        using Monoid=typename MUStruct::Monoid;
        using Update=typename MUStruct::Update;
        using value_t=typename Monoid::value_t;
        using update_t=typename Update::update_t;

        protected:

        int N;
        std::vector<value_t> dat;
        std::vector<update_t> lazy;
        std::vector<char> flag;

        static int calcN(int n){int res=1; while(res<n) res*=2; return res;};
        void propagate(int node);
        void applyLazy(int node,update_t x);
        void applyImpl(int l,int r,int k,int lb,int ub,update_t f);
        void updateImpl(int pos,int k,int lb,int ub,value_t x);
        value_t queryImpl(int l,int r,int k,int lb,int ub);
        value_t getValue(int node){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node]) : dat[node];}

        public:
        LazySegmentTree(int N);
        void apply(int l,int r,update_t f);
        void updateALL(std::vector<value_t> x);
        void update(int pos,value_t v);
        value_t query(int a,int b);
    };

    // struct MUStructExample{
    //     struct Monoid{
    //         using value_t=int;
    //         static constexpr value_t E(){return 1e9;}
    //         static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    //     };
    //     struct Update{
    //         using update_t = int;
    //         static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    //     };
    //     static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
    // };

    template<class MUStruct>
    LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::propagate(int node){
        if(flag[node]){
            flag[node]=false;
            applyLazy(node*2+1,lazy[node]);
            applyLazy(node*2+2,lazy[node]);
            dat[node]=Monoid::op(getValue(node*2+1),getValue(node*2+2));
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
        if(flag[node]){
            lazy[node]=Update::op(lazy[node],x);
        }
        else{
            flag[node]=true;
            lazy[node]=x;
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyImpl(int l,int r,int k,int lb,int ub,update_t x){
        if(r<=lb || ub<=l) return;
        if(l<=lb && ub<=r){
            applyLazy(k,x);
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        applyImpl(l,r,k*2+1,lb,mid,x);
        applyImpl(l,r,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateImpl(int pos,int k,int lb,int ub,value_t x){
        if(!(lb<=pos && pos<ub))return;
        if(pos==lb && pos==ub-1){
            flag[k]=false;
            dat[k]=x;
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        updateImpl(pos,k*2+1,lb,mid,x);
        updateImpl(pos,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
        if(r<=lb || ub<=l) return Monoid::E();
        if(l<=lb && ub<=r){
            return getValue(k);
        }
        propagate(k);
        int mid=(lb+ub)/2;
        value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
        value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
        return Monoid::op(lhs,rhs);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::apply(int l,int r,update_t x){
        applyImpl(l,r,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::update(int pos,value_t x){
        updateImpl(pos,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateALL(std::vector<value_t> xs){
        for(int i=0;i<xs.size();i++){
            dat[i+N-1]=xs[i];
        }
        for(int i=xs.size();i<N;i++) dat[i+N-1]=Monoid::E(),flag[i+N-1]=false;
        for(int i=N-2;i>=0;i--){
            flag[i]=false;
            value_t c1v=dat[i*2+1],c2v=dat[i*2+2];
            dat[i]=Monoid::op(c1v,c2v);
        }
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
        return queryImpl(l,r,0,0,N);
    }
};

namespace ProconLib{

    template<typename MUStruct>
    class BSLazySegmentTree:public LazySegmentTree<MUStruct>{
        public:
        using LazySegmentTree<MUStruct>::N;
        using typename LazySegmentTree<MUStruct>::value_t;
        using typename LazySegmentTree<MUStruct>::Monoid;
        using LazySegmentTree<MUStruct>::getValue;
        using LazySegmentTree<MUStruct>::propagate;
        protected:
        template<typename Judge>
        int searchImpl(int l,int k,int lb,int ub,value_t& v){
            if(ub<=l) return N+1;
            if(k>=N-1){
                v=Monoid::op(v,getValue(k));
                return Judge::op(v) ? ub : N+1;
            }
            propagate(k);
            int mid=(lb+ub)/2;
            if(lb<l){
                int ret=searchImpl<Judge>(l,k*2+1,lb,mid,v);
                if(ret<=N) return ret;
                if(Judge::op(Monoid::op(v,getValue(k*2+2)))){
                    return searchImpl<Judge>(l,k*2+2,mid,ub,v);
                }
                else{
                    v=Monoid::op(v,getValue(k*2+2));
                    return N+1;
                }
            }
            else{
                if(Judge::op(Monoid::op(v,getValue(k*2+1)))){
                    return searchImpl<Judge>(l,k*2+1,lb,mid,v);
                }
                else{
                    v=Monoid::op(v,getValue(k*2+2));
                    return searchImpl<Judge>(l,k*2+2,mid,ub,v);
                }
            }
        }

        public:
        BSLazySegmentTree(int N):LazySegmentTree<MUStruct>(N){}
        // return r
        // s.t.
        // judge(query(l,i))==false if i<r
        // judge(query(l,i))==true  if r<=i<=N
        template<typename Judge>
        int search(int l){
            if(Judge::op(Monoid::E())) return l;
            value_t v=Monoid::E();
            return searchImpl<Judge>(l,0,0,N,v);
        }
    };
}
struct MUStruct{
    struct Monoid{
        using value_t=int;
        static constexpr value_t E(){return 1e9;}
        static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    };
    struct Update{
        using update_t = int;
        static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    };
    static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
};

map<int,int> compress(vector<int> v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<int,int> res;
    for(int i=0;i<v.size();i++){
        res[v[v.size()-i-1]]=i;
    }

    return res;
}

using namespace ProconLib;
struct Judge{
    static bool op(int v){
        return v<0;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> b(m);
    for(int i=0;i<m;i++) cin>>b[i];
    int q;
    cin>>q;
    vector<int> type(q),id(q),x(q);
    for(int i=0;i<q;i++){
        cin>>type[i]>>id[i]>>x[i];
        id[i]--;
    }
    // cerr<<"#Input finished"<<endl;
    map<int,int> mp;
    {
        vector<int> tmp=a;
        tmp.insert(tmp.end(),b.begin(),b.end());
        tmp.insert(tmp.end(),x.begin(),x.end());
        mp=compress(tmp);
    }
    int sz=mp.size();
    // cerr<<"#Compressed "<<sz<<endl;
    vector<int> vs(sz);
    for(auto &e:mp){
        // cerr<<e.second<<" "<<e.first<<endl;
        vs[e.second]=e.first;
    }

    BSLazySegmentTree<MUStruct> seg(sz);
    for(int i=0;i<sz;i++) seg.update(i,0);
    for(int i=0;i<n;i++){
        seg.apply(mp[a[i]],sz,-1);
    }

    for(int i=0;i<m;i++){
        seg.apply(mp[b[i]],sz,1);
    }
    auto calc=[&](){
        return seg.search<Judge>(0);
    };
    for(int i=0;i<q;i++){
        if(type[i]==1){
            seg.apply(mp[a[id[i]]],sz,1);
            seg.apply(mp[x[i]],sz,-1);
            a[id[i]]=x[i];
        }
        else{
            seg.apply(mp[b[id[i]]],sz,-1);
            seg.apply(mp[x[i]],sz,1);
            b[id[i]]=x[i];
        }
        // cerr<<seg.query(0,3)<<endl;
        // cerr<<"#"<<seg.query(0,sz)<<endl;
        int v=calc();
        // cerr<<"#"<<v<<endl;
        cout<<(v>sz ? -1 : vs[v-1])<<"\n";
    }

    return 0;
}


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

    template<class MUStruct>
    class LazySegmentTree{
        public:
        using Monoid=typename MUStruct::Monoid;
        using Update=typename MUStruct::Update;
        using value_t=typename Monoid::value_t;
        using update_t=typename Update::update_t;

        private:

        int N;
        std::vector<value_t> dat;
        std::vector<update_t> lazy;
        std::vector<char> flag;

        static int calcN(int n){int res=1; while(res<n) res*=2; return res;};
        void propagate(int node);
        void applyLazy(int node,update_t x);
        void applyImpl(int l,int r,int k,int lb,int ub,update_t f);
        void updateImpl(int pos,int k,int lb,int ub,value_t x);
        value_t queryImpl(int l,int r,int k,int lb,int ub);
        value_t getValue(int node){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node]) : dat[node];}

        public:
        LazySegmentTree(int N);
        void apply(int l,int r,update_t f);
        void updateALL(std::vector<value_t> x);
        void update(int pos,value_t v);
        value_t query(int a,int b);

        value_t BSquery(int k,int lb,int ub){
            if(k>=N-1) return lb;
            propagate(k);
            int mid=(lb+ub)/2;
            if(getValue(2*k+1)<0) return BSquery(k*2+1,lb,mid);
            assert(getValue(2*k+2<0));
            return BSquery(k*2+2,mid,ub);
        }
    };

    template<class MUStruct>
    LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::propagate(int node){
        if(flag[node]){
            flag[node]=false;
            applyLazy(node*2+1,lazy[node]);
            applyLazy(node*2+2,lazy[node]);
            dat[node]=Monoid::op(getValue(node*2+1),getValue(node*2+2));
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
        if(flag[node]){
            lazy[node]=Update::op(lazy[node],x);
        }
        else{
            flag[node]=true;
            lazy[node]=x;
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyImpl(int l,int r,int k,int lb,int ub,update_t x){
        if(r<=lb || ub<=l) return;
        if(l<=lb && ub<=r){
            applyLazy(k,x);
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        applyImpl(l,r,k*2+1,lb,mid,x);
        applyImpl(l,r,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateImpl(int pos,int k,int lb,int ub,value_t x){
        if(!(lb<=pos && pos<ub))return;
        if(pos==lb && pos==ub-1){
            flag[k]=false;
            dat[k]=x;
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        updateImpl(pos,k*2+1,lb,mid,x);
        updateImpl(pos,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
        if(r<=lb || ub<=l) return Monoid::E();
        if(l<=lb && ub<=r){
            return getValue(k);
        }
        propagate(k);
        int mid=(lb+ub)/2;
        value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
        value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
        return Monoid::op(lhs,rhs);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::apply(int l,int r,update_t x){
        applyImpl(l,r,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::update(int pos,value_t x){
        updateImpl(pos,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateALL(std::vector<value_t> xs){
        for(int i=0;i<xs.size();i++){
            dat[i+N-1]=xs[i];
        }
        for(int i=xs.size();i<N;i++) dat[i+N-1]=Monoid::E(),flag[i+N-1]=false;
        for(int i=N-2;i>=0;i--){
            flag[i]=false;
            value_t c1v=dat[i*2+1],c2v=dat[i*2+2];
            dat[i]=Monoid::op(c1v,c2v);
        }
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
        return queryImpl(l,r,0,0,N);
    }
};

struct MUStruct{
    struct Monoid{
        using value_t=int;
        static constexpr value_t E(){return 1e9;}
        static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    };
    struct Update{
        using update_t = int;
        static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    };
    static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
};

map<int,int> compress(vector<int> v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<int,int> res;
    for(int i=0;i<v.size();i++){
        res[v[v.size()-i-1]]=i;
    }

    return res;
}

using namespace ProconLib;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> b(m);
    for(int i=0;i<m;i++) cin>>b[i];
    int q;
    cin>>q;
    vector<int> type(q),id(q),x(q);
    for(int i=0;i<q;i++){
        cin>>type[i]>>id[i]>>x[i];
        id[i]--;
    }
    // cerr<<"#Input finished"<<endl;
    map<int,int> mp;
    {
        vector<int> tmp=a;
        tmp.insert(tmp.end(),b.begin(),b.end());
        // cerr<<"#"<<endl;
        tmp.insert(tmp.end(),x.begin(),x.end());
        mp=compress(tmp);
    }
    int sz=mp.size();
    // cerr<<"#Compressed "<<sz<<endl;
    vector<int> vs(sz);
    for(auto &e:mp){
        vs[e.second]=e.first;
    }
    LazySegmentTree<MUStruct> seg(sz);
    for(int i=0;i<sz;i++) seg.update(i,0);
    for(int i=0;i<n;i++){
        seg.apply(mp[a[i]],sz,-1);
    }

    for(int i=0;i<m;i++){
        seg.apply(mp[b[i]],sz,1);
    }
    auto calc=[&](){
        if(seg.query(0,sz)>=0) return -1;
        else return seg.BSquery(0,0,sz);
    };
    for(int i=0;i<q;i++){
        if(type[i]==1){
            seg.apply(mp[a[id[i]]],sz,1);
            seg.apply(mp[x[i]],sz,-1);
            a[id[i]]=x[i];
        }
        else{
            seg.apply(mp[b[id[i]]],sz,-1);
            seg.apply(mp[x[i]],sz,1);
            b[id[i]]=x[i];
        }
        // cerr<<"#"<<seg.query(0,sz)<<endl;
        int v=calc();
        // cerr<<"#"<<endl;
        cout<<(v<0 ? -1 : vs[v])<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
#include<vector>
// #include"../proconLib/DataStructure/BSLazySegmentTree.cpp"
using namespace std;

namespace ProconLib{

    template<class MUStruct>
    class LazySegmentTree{
        public:
        using Monoid=typename MUStruct::Monoid;
        using Update=typename MUStruct::Update;
        using value_t=typename Monoid::value_t;
        using update_t=typename Update::update_t;

        protected:

        int N;
        std::vector<value_t> dat;
        std::vector<update_t> lazy;
        std::vector<char> flag;

        static int calcN(int n){int res=1; while(res<n) res*=2; return res;};
        void propagate(int node);
        void applyLazy(int node,update_t x);
        void applyImpl(int l,int r,int k,int lb,int ub,update_t f);
        void updateImpl(int pos,int k,int lb,int ub,value_t x);
        value_t queryImpl(int l,int r,int k,int lb,int ub);
        value_t getValue(int node){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node]) : dat[node];}

        public:
        LazySegmentTree(int N);
        void apply(int l,int r,update_t f);
        void updateALL(std::vector<value_t> x);
        void update(int pos,value_t v);
        value_t query(int a,int b);
    };

    // struct MUStructExample{
    //     struct Monoid{
    //         using value_t=int;
    //         static constexpr value_t E(){return 1e9;}
    //         static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    //     };
    //     struct Update{
    //         using update_t = int;
    //         static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    //     };
    //     static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
    // };

    template<class MUStruct>
    LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::propagate(int node){
        if(flag[node]){
            flag[node]=false;
            applyLazy(node*2+1,lazy[node]);
            applyLazy(node*2+2,lazy[node]);
            dat[node]=Monoid::op(getValue(node*2+1),getValue(node*2+2));
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
        if(flag[node]){
            lazy[node]=Update::op(lazy[node],x);
        }
        else{
            flag[node]=true;
            lazy[node]=x;
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyImpl(int l,int r,int k,int lb,int ub,update_t x){
        if(r<=lb || ub<=l) return;
        if(l<=lb && ub<=r){
            applyLazy(k,x);
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        applyImpl(l,r,k*2+1,lb,mid,x);
        applyImpl(l,r,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateImpl(int pos,int k,int lb,int ub,value_t x){
        if(!(lb<=pos && pos<ub))return;
        if(pos==lb && pos==ub-1){
            flag[k]=false;
            dat[k]=x;
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        updateImpl(pos,k*2+1,lb,mid,x);
        updateImpl(pos,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
        if(r<=lb || ub<=l) return Monoid::E();
        if(l<=lb && ub<=r){
            return getValue(k);
        }
        propagate(k);
        int mid=(lb+ub)/2;
        value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
        value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
        return Monoid::op(lhs,rhs);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::apply(int l,int r,update_t x){
        applyImpl(l,r,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::update(int pos,value_t x){
        updateImpl(pos,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateALL(std::vector<value_t> xs){
        for(int i=0;i<xs.size();i++){
            dat[i+N-1]=xs[i];
        }
        for(int i=xs.size();i<N;i++) dat[i+N-1]=Monoid::E(),flag[i+N-1]=false;
        for(int i=N-2;i>=0;i--){
            flag[i]=false;
            value_t c1v=dat[i*2+1],c2v=dat[i*2+2];
            dat[i]=Monoid::op(c1v,c2v);
        }
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
        return queryImpl(l,r,0,0,N);
    }
};

namespace ProconLib{

    template<typename MUStruct>
    class BSLazySegmentTree:public LazySegmentTree<MUStruct>{
        public:
        using LazySegmentTree<MUStruct>::N;
        using typename LazySegmentTree<MUStruct>::value_t;
        using typename LazySegmentTree<MUStruct>::Monoid;
        using LazySegmentTree<MUStruct>::getValue;
        using LazySegmentTree<MUStruct>::propagate;
        protected:
        template<typename Judge>
        int searchImpl(int l,int k,int lb,int ub,value_t& v){
            if(ub<=l) return N+1;
            if(k>=N-1){
                v=Monoid::op(v,getValue(k));
                return Judge::op(v) ? ub : N+1;
            }
            propagate(k);
            int mid=(lb+ub)/2;
            if(lb<l){
                int ret=searchImpl<Judge>(l,k*2+1,lb,mid,v);
                if(ret<=N) return ret;
                return searchImpl<Judge>(l,k*2+1,mid,ub,v);
            }
            else{
                if(Monoid::op(v,getValue(k*2+1))){
                    return searchImpl<Judge>(l,k*2+1,lb,mid,v);
                }
                else{
                    v=Monoid::op(v,getValue(k*2+2));
                    return searchImpl<Judge>(l,k*2+2,mid,ub,v);
                }
            }
        }

        public:
        BSLazySegmentTree(int N):LazySegmentTree<MUStruct>(N){}
        // return r
        // s.t.
        // judge(query(l,i))==false if i<r
        // judge(query(l,i))==true  if r<=i<=N
        template<typename Judge>
        int search(int l){
            if(Judge::op(Monoid::E())) return l;
            value_t v=Monoid::E();
            return searchImpl<Judge>(l,0,0,N,v);
        }
    };
};

struct MUStruct{
    struct Monoid{
        using value_t=int;
        static constexpr value_t E(){return 1e9;}
        static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    };
    struct Update{
        using update_t = int;
        static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    };
    static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
};

map<int,int> compress(vector<int> v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<int,int> res;
    for(int i=0;i<v.size();i++){
        res[v[v.size()-i-1]]=i;
    }

    return res;
}

using namespace ProconLib;
struct Judge{
    static bool op(int v){
        return v<0;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> b(m);
    for(int i=0;i<m;i++) cin>>b[i];
    int q;
    cin>>q;
    vector<int> type(q),id(q),x(q);
    for(int i=0;i<q;i++){
        cin>>type[i]>>id[i]>>x[i];
        id[i]--;
    }
    // cerr<<"#Input finished"<<endl;
    map<int,int> mp;
    {
        vector<int> tmp=a;
        tmp.insert(tmp.end(),b.begin(),b.end());
        tmp.insert(tmp.end(),x.begin(),x.end());
        mp=compress(tmp);
    }
    int sz=mp.size();
    // cerr<<"#Compressed "<<sz<<endl;
    vector<int> vs(sz);
    for(auto &e:mp){
        // cerr<<e.second<<" "<<e.first<<endl;
        vs[e.second]=e.first;
    }

    BSLazySegmentTree<MUStruct> seg(sz);
    for(int i=0;i<sz;i++) seg.update(i,0);
    for(int i=0;i<n;i++){
        seg.apply(mp[a[i]],sz,-1);
    }

    for(int i=0;i<m;i++){
        seg.apply(mp[b[i]],sz,1);
    }
    auto calc=[&](){
        return seg.search<Judge>(0);
    };
    for(int i=0;i<q;i++){
        if(type[i]==1){
            seg.apply(mp[a[id[i]]],sz,1);
            seg.apply(mp[x[i]],sz,-1);
            a[id[i]]=x[i];
        }
        else{
            seg.apply(mp[b[id[i]]],sz,-1);
            seg.apply(mp[x[i]],sz,1);
            b[id[i]]=x[i];
        }
        // cerr<<seg.query(0,3)<<endl;
        // cerr<<"#"<<seg.query(0,sz)<<endl;
        int v=calc();
        // cerr<<"#"<<v<<endl;
        cout<<(v>sz ? -1 : vs[v-1])<<"\n";
    }

    return 0;
}


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

    template<class MUStruct>
    class LazySegmentTree{
        public:
        using Monoid=typename MUStruct::Monoid;
        using Update=typename MUStruct::Update;
        using value_t=typename Monoid::value_t;
        using update_t=typename Update::update_t;

        private:

        int N;
        std::vector<value_t> dat;
        std::vector<update_t> lazy;
        std::vector<char> flag;

        static int calcN(int n){int res=1; while(res<n) res*=2; return res;};
        void propagate(int node);
        void applyLazy(int node,update_t x);
        void applyImpl(int l,int r,int k,int lb,int ub,update_t f);
        void updateImpl(int pos,int k,int lb,int ub,value_t x);
        value_t queryImpl(int l,int r,int k,int lb,int ub);
        value_t getValue(int node){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node]) : dat[node];}

        public:
        LazySegmentTree(int N);
        void apply(int l,int r,update_t f);
        void updateALL(std::vector<value_t> x);
        void update(int pos,value_t v);
        value_t query(int a,int b);

        value_t BSquery(int k,int lb,int ub){
            if(k>=N-1) return lb;
            propagate(k);
            int mid=(lb+ub)/2;
            if(getValue(2*k+1)<0) return BSquery(k*2+1,lb,mid);
            assert(getValue(2*k+2<0));
            return BSquery(k*2+2,mid,ub);
        }
    };

    template<class MUStruct>
    LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::propagate(int node){
        if(flag[node]){
            flag[node]=false;
            applyLazy(node*2+1,lazy[node]);
            applyLazy(node*2+2,lazy[node]);
            dat[node]=Monoid::op(getValue(node*2+1),getValue(node*2+2));
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
        if(flag[node]){
            lazy[node]=Update::op(lazy[node],x);
        }
        else{
            flag[node]=true;
            lazy[node]=x;
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyImpl(int l,int r,int k,int lb,int ub,update_t x){
        if(r<=lb || ub<=l) return;
        if(l<=lb && ub<=r){
            applyLazy(k,x);
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        applyImpl(l,r,k*2+1,lb,mid,x);
        applyImpl(l,r,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateImpl(int pos,int k,int lb,int ub,value_t x){
        if(!(lb<=pos && pos<ub))return;
        if(pos==lb && pos==ub-1){
            flag[k]=false;
            dat[k]=x;
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        updateImpl(pos,k*2+1,lb,mid,x);
        updateImpl(pos,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
        if(r<=lb || ub<=l) return Monoid::E();
        if(l<=lb && ub<=r){
            return getValue(k);
        }
        propagate(k);
        int mid=(lb+ub)/2;
        value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
        value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
        return Monoid::op(lhs,rhs);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::apply(int l,int r,update_t x){
        applyImpl(l,r,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::update(int pos,value_t x){
        updateImpl(pos,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateALL(std::vector<value_t> xs){
        for(int i=0;i<xs.size();i++){
            dat[i+N-1]=xs[i];
        }
        for(int i=xs.size();i<N;i++) dat[i+N-1]=Monoid::E(),flag[i+N-1]=false;
        for(int i=N-2;i>=0;i--){
            flag[i]=false;
            value_t c1v=dat[i*2+1],c2v=dat[i*2+2];
            dat[i]=Monoid::op(c1v,c2v);
        }
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
        return queryImpl(l,r,0,0,N);
    }
};

struct MUStruct{
    struct Monoid{
        using value_t=int;
        static constexpr value_t E(){return 0;}
        static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    };
    struct Update{
        using update_t = int;
        static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    };
    static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
};

map<int,int> compress(vector<int> v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<int,int> res;
    for(int i=0;i<v.size();i++){
        res[v[v.size()-i-1]]=i;
    }

    return res;
}

using namespace ProconLib;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> b(m);
    for(int i=0;i<m;i++) cin>>b[i];
    int q;
    cin>>q;
    vector<int> type(q),id(q),x(q);
    for(int i=0;i<q;i++){
        cin>>type[i]>>id[i]>>x[i];
        id[i]--;
    }
    // cerr<<"#Input finished"<<endl;
    map<int,int> mp;
    {
        vector<int> tmp=a;
        tmp.insert(tmp.end(),b.begin(),b.end());
        // cerr<<"#"<<endl;
        tmp.insert(tmp.end(),x.begin(),x.end());
        mp=compress(tmp);
    }
    int sz=mp.size();
    // cerr<<"#Compressed "<<sz<<endl;
    vector<int> vs(sz);
    for(auto &e:mp){
        vs[e.second]=e.first;
    }
    LazySegmentTree<MUStruct> seg(sz);
    for(int i=0;i<n;i++){
        seg.apply(mp[a[i]],sz,-1);
    }

    for(int i=0;i<m;i++){
        seg.apply(mp[b[i]],sz,1);
    }
    auto calc=[&](){
        if(seg.query(0,sz)>=0) return -1;
        else return seg.BSquery(0,0,sz);
    };
    for(int i=0;i<q;i++){
        if(type[i]==1){
            seg.apply(mp[a[id[i]]],sz,1);
            seg.apply(mp[x[i]],sz,-1);
            a[id[i]]=x[i];
        }
        else{
            seg.apply(mp[b[id[i]]],sz,-1);
            seg.apply(mp[x[i]],sz,1);
            b[id[i]]=x[i];
        }
        // cerr<<"#"<<seg.query(0,sz)<<endl;
        int v=calc();
        // cerr<<"#"<<endl;
        cout<<(v<0 ? -1 : vs[v])<<"\n";
    }

    return 0;
}


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

namespace ProconLib{

    template<class MUStruct>
    class LazySegmentTree{
        public:
        using Monoid=typename MUStruct::Monoid;
        using Update=typename MUStruct::Update;
        using value_t=typename Monoid::value_t;
        using update_t=typename Update::update_t;

        protected:

        int N;
        std::vector<value_t> dat;
        std::vector<update_t> lazy;
        std::vector<char> flag;

        static int calcN(int n){int res=1; while(res<n) res*=2; return res;};
        void propagate(int node);
        void applyLazy(int node,update_t x);
        void applyImpl(int l,int r,int k,int lb,int ub,update_t f);
        void updateImpl(int pos,int k,int lb,int ub,value_t x);
        value_t queryImpl(int l,int r,int k,int lb,int ub);
        value_t getValue(int node){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node]) : dat[node];}

        public:
        LazySegmentTree(int N);
        void apply(int l,int r,update_t f);
        void updateALL(std::vector<value_t> x);
        void update(int pos,value_t v);
        value_t query(int a,int b);
    };

    // struct MUStructExample{
    //     struct Monoid{
    //         using value_t=int;
    //         static constexpr value_t E(){return 1e9;}
    //         static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    //     };
    //     struct Update{
    //         using update_t = int;
    //         static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    //     };
    //     static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
    // };

    template<class MUStruct>
    LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::propagate(int node){
        if(flag[node]){
            flag[node]=false;
            applyLazy(node*2+1,lazy[node]);
            applyLazy(node*2+2,lazy[node]);
            dat[node]=Monoid::op(getValue(node*2+1),getValue(node*2+2));
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
        if(flag[node]){
            lazy[node]=Update::op(lazy[node],x);
        }
        else{
            flag[node]=true;
            lazy[node]=x;
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyImpl(int l,int r,int k,int lb,int ub,update_t x){
        if(r<=lb || ub<=l) return;
        if(l<=lb && ub<=r){
            applyLazy(k,x);
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        applyImpl(l,r,k*2+1,lb,mid,x);
        applyImpl(l,r,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateImpl(int pos,int k,int lb,int ub,value_t x){
        if(!(lb<=pos && pos<ub))return;
        if(pos==lb && pos==ub-1){
            flag[k]=false;
            dat[k]=x;
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        updateImpl(pos,k*2+1,lb,mid,x);
        updateImpl(pos,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
        if(r<=lb || ub<=l) return Monoid::E();
        if(l<=lb && ub<=r){
            return getValue(k);
        }
        propagate(k);
        int mid=(lb+ub)/2;
        value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
        value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
        return Monoid::op(lhs,rhs);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::apply(int l,int r,update_t x){
        applyImpl(l,r,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::update(int pos,value_t x){
        updateImpl(pos,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateALL(std::vector<value_t> xs){
        for(int i=0;i<xs.size();i++){
            dat[i+N-1]=xs[i];
        }
        for(int i=xs.size();i<N;i++) dat[i+N-1]=Monoid::E(),flag[i+N-1]=false;
        for(int i=N-2;i>=0;i--){
            flag[i]=false;
            value_t c1v=dat[i*2+1],c2v=dat[i*2+2];
            dat[i]=Monoid::op(c1v,c2v);
        }
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
        return queryImpl(l,r,0,0,N);
    }
};

namespace ProconLib{

    template<typename MUStruct>
    class BSLazySegmentTree:public LazySegmentTree<MUStruct>{
        public:
        using LazySegmentTree<MUStruct>::N;
        using typename LazySegmentTree<MUStruct>::value_t;
        using typename LazySegmentTree<MUStruct>::Monoid;
        using LazySegmentTree<MUStruct>::getValue;
        using LazySegmentTree<MUStruct>::propagate;
        protected:
        template<typename Judge>
        int searchImpl(int l,int k,int lb,int ub,value_t& v){
            if(ub<=l) return N+1;
            if(k>=N-1){
                v=Monoid::op(v,getValue(k));
                return Judge::op(v) ? ub : N+1;
            }
            propagate(k);
            int mid=(lb+ub)/2;
            if(lb<l){
                int ret=searchImpl<Judge>(l,k*2+1,lb,mid,v);
                if(ret<=N) return ret;
                if(Judge::op(Monoid::op(v,getValue(k*2+2)))){
                    return searchImpl<Judge>(l,k*2+2,mid,ub,v);
                }
                else{
                    v=Monoid::op(v,getValue(k*2+2));
                    return N+1;
                }
            }
            else{
                if(Judge::op(Monoid::op(v,getValue(k*2+1)))){
                    return searchImpl<Judge>(l,k*2+1,lb,mid,v);
                }
                else{
                    v=Monoid::op(v,getValue(k*2+1));
                    return searchImpl<Judge>(l,k*2+2,mid,ub,v);
                }
            }
        }

        public:
        BSLazySegmentTree(int N):LazySegmentTree<MUStruct>(N){}
        // return r
        // s.t.
        // judge(query(l,i))==false if i<r
        // judge(query(l,i))==true  if r<=i<=N
        template<typename Judge>
        int search(int l){
            if(Judge::op(Monoid::E())) return l;
            value_t v=Monoid::E();
            return searchImpl<Judge>(l,0,0,N,v);
        }
    };
}
struct MUStruct{
    struct Monoid{
        using value_t=int;
        static constexpr value_t E(){return 1e9;}
        static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    };
    struct Update{
        using update_t = int;
        static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    };
    static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
};

map<int,int> compress(vector<int> v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<int,int> res;
    for(int i=0;i<v.size();i++){
        res[v[v.size()-i-1]]=i;
    }

    return res;
}

using namespace ProconLib;
struct Judge{
    static bool op(int v){
        return v<0;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> b(m);
    for(int i=0;i<m;i++) cin>>b[i];
    int q;
    cin>>q;
    vector<int> type(q),id(q),x(q);
    for(int i=0;i<q;i++){
        cin>>type[i]>>id[i]>>x[i];
        id[i]--;
    }
    // cerr<<"#Input finished"<<endl;
    map<int,int> mp;
    {
        vector<int> tmp=a;
        tmp.insert(tmp.end(),b.begin(),b.end());
        tmp.insert(tmp.end(),x.begin(),x.end());
        mp=compress(tmp);
    }
    int sz=mp.size();
    // cerr<<"#Compressed "<<sz<<endl;
    vector<int> vs(sz);
    for(auto &e:mp){
        // cerr<<e.second<<" "<<e.first<<endl;
        vs[e.second]=e.first;
    }

    BSLazySegmentTree<MUStruct> seg(sz);
    for(int i=0;i<sz;i++) seg.update(i,0);
    for(int i=0;i<n;i++){
        seg.apply(mp[a[i]],sz,-1);
    }

    for(int i=0;i<m;i++){
        seg.apply(mp[b[i]],sz,1);
    }
    auto calc=[&](){
        return seg.search<Judge>(0);
    };
    for(int i=0;i<q;i++){
        if(type[i]==1){
            seg.apply(mp[a[id[i]]],sz,1);
            seg.apply(mp[x[i]],sz,-1);
            a[id[i]]=x[i];
        }
        else{
            seg.apply(mp[b[id[i]]],sz,-1);
            seg.apply(mp[x[i]],sz,1);
            b[id[i]]=x[i];
        }
        // cerr<<seg.query(0,3)<<endl;
        // cerr<<"#"<<seg.query(0,sz)<<endl;
        int v=calc();
        // cerr<<"#"<<v<<endl;
        cout<<(v>sz ? -1 : vs[v-1])<<"\n";
    }

    return 0;
}


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

namespace ProconLib{

    template<class MUStruct>
    class LazySegmentTree{
        public:
        using Monoid=typename MUStruct::Monoid;
        using Update=typename MUStruct::Update;
        using value_t=typename Monoid::value_t;
        using update_t=typename Update::update_t;

        protected:

        int N;
        std::vector<value_t> dat;
        std::vector<update_t> lazy;
        std::vector<char> flag;

        static int calcN(int n){int res=1; while(res<n) res*=2; return res;};
        void propagate(int node);
        void applyLazy(int node,update_t x);
        void applyImpl(int l,int r,int k,int lb,int ub,update_t f);
        void updateImpl(int pos,int k,int lb,int ub,value_t x);
        value_t queryImpl(int l,int r,int k,int lb,int ub);
        value_t getValue(int node){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node]) : dat[node];}

        public:
        LazySegmentTree(int N);
        void apply(int l,int r,update_t f);
        void updateALL(std::vector<value_t> x);
        void update(int pos,value_t v);
        value_t query(int a,int b);
    };

    // struct MUStructExample{
    //     struct Monoid{
    //         using value_t=int;
    //         static constexpr value_t E(){return 1e9;}
    //         static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    //     };
    //     struct Update{
    //         using update_t = int;
    //         static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    //     };
    //     static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
    // };

    template<class MUStruct>
    LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::propagate(int node){
        if(flag[node]){
            flag[node]=false;
            applyLazy(node*2+1,lazy[node]);
            applyLazy(node*2+2,lazy[node]);
            dat[node]=Monoid::op(getValue(node*2+1),getValue(node*2+2));
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
        if(flag[node]){
            lazy[node]=Update::op(lazy[node],x);
        }
        else{
            flag[node]=true;
            lazy[node]=x;
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyImpl(int l,int r,int k,int lb,int ub,update_t x){
        if(r<=lb || ub<=l) return;
        if(l<=lb && ub<=r){
            applyLazy(k,x);
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        applyImpl(l,r,k*2+1,lb,mid,x);
        applyImpl(l,r,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateImpl(int pos,int k,int lb,int ub,value_t x){
        if(!(lb<=pos && pos<ub))return;
        if(pos==lb && pos==ub-1){
            flag[k]=false;
            dat[k]=x;
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        updateImpl(pos,k*2+1,lb,mid,x);
        updateImpl(pos,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
        if(r<=lb || ub<=l) return Monoid::E();
        if(l<=lb && ub<=r){
            return getValue(k);
        }
        propagate(k);
        int mid=(lb+ub)/2;
        value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
        value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
        return Monoid::op(lhs,rhs);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::apply(int l,int r,update_t x){
        applyImpl(l,r,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::update(int pos,value_t x){
        updateImpl(pos,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateALL(std::vector<value_t> xs){
        for(int i=0;i<xs.size();i++){
            dat[i+N-1]=xs[i];
        }
        for(int i=xs.size();i<N;i++) dat[i+N-1]=Monoid::E(),flag[i+N-1]=false;
        for(int i=N-2;i>=0;i--){
            flag[i]=false;
            value_t c1v=dat[i*2+1],c2v=dat[i*2+2];
            dat[i]=Monoid::op(c1v,c2v);
        }
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
        return queryImpl(l,r,0,0,N);
    }
};

namespace ProconLib{

    template<typename MUStruct>
    class BSLazySegmentTree:public LazySegmentTree<MUStruct>{
        public:
        using LazySegmentTree<MUStruct>::N;
        using typename LazySegmentTree<MUStruct>::value_t;
        using typename LazySegmentTree<MUStruct>::Monoid;
        using LazySegmentTree<MUStruct>::getValue;
        using LazySegmentTree<MUStruct>::propagate;
        protected:
        template<typename Judge>
        int searchImpl(int l,int k,int lb,int ub,value_t& v){
            if(ub<=l) return N+1;
            if(k>=N-1){
                v=Monoid::op(v,getValue(k));
                return Judge::op(v) ? ub : N+1;
            }
            propagate(k);
            int mid=(lb+ub)/2;
            if(lb<l){
                int ret=searchImpl<Judge>(l,k*2+1,lb,mid,v);
                if(ret<=N) return ret;
                return searchImpl<Judge>(l,k*2+2,mid,ub,v);
            }
            else{
                if(Monoid::op(v,getValue(k*2+1))){
                    return searchImpl<Judge>(l,k*2+1,lb,mid,v);
                }
                else{
                    v=Monoid::op(v,getValue(k*2+2));
                    return searchImpl<Judge>(l,k*2+2,mid,ub,v);
                }
            }
        }

        public:
        BSLazySegmentTree(int N):LazySegmentTree<MUStruct>(N){}
        // return r
        // s.t.
        // judge(query(l,i))==false if i<r
        // judge(query(l,i))==true  if r<=i<=N
        template<typename Judge>
        int search(int l){
            if(Judge::op(Monoid::E())) return l;
            value_t v=Monoid::E();
            return searchImpl<Judge>(l,0,0,N,v);
        }
    };
};

struct MUStruct{
    struct Monoid{
        using value_t=int;
        static constexpr value_t E(){return 1e9;}
        static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    };
    struct Update{
        using update_t = int;
        static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    };
    static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
};

map<int,int> compress(vector<int> v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<int,int> res;
    for(int i=0;i<v.size();i++){
        res[v[v.size()-i-1]]=i;
    }

    return res;
}

using namespace ProconLib;
struct Judge{
    static bool op(int v){
        return v<0;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> b(m);
    for(int i=0;i<m;i++) cin>>b[i];
    int q;
    cin>>q;
    vector<int> type(q),id(q),x(q);
    for(int i=0;i<q;i++){
        cin>>type[i]>>id[i]>>x[i];
        id[i]--;
    }
    // cerr<<"#Input finished"<<endl;
    map<int,int> mp;
    {
        vector<int> tmp=a;
        tmp.insert(tmp.end(),b.begin(),b.end());
        tmp.insert(tmp.end(),x.begin(),x.end());
        mp=compress(tmp);
    }
    int sz=mp.size();
    // cerr<<"#Compressed "<<sz<<endl;
    vector<int> vs(sz);
    for(auto &e:mp){
        // cerr<<e.second<<" "<<e.first<<endl;
        vs[e.second]=e.first;
    }

    BSLazySegmentTree<MUStruct> seg(sz);
    for(int i=0;i<sz;i++) seg.update(i,0);
    for(int i=0;i<n;i++){
        seg.apply(mp[a[i]],sz,-1);
    }

    for(int i=0;i<m;i++){
        seg.apply(mp[b[i]],sz,1);
    }
    auto calc=[&](){
        return seg.search<Judge>(0);
    };
    for(int i=0;i<q;i++){
        if(type[i]==1){
            seg.apply(mp[a[id[i]]],sz,1);
            seg.apply(mp[x[i]],sz,-1);
            a[id[i]]=x[i];
        }
        else{
            seg.apply(mp[b[id[i]]],sz,-1);
            seg.apply(mp[x[i]],sz,1);
            b[id[i]]=x[i];
        }
        // cerr<<seg.query(0,3)<<endl;
        // cerr<<"#"<<seg.query(0,sz)<<endl;
        int v=calc();
        // cerr<<"#"<<v<<endl;
        cout<<(v>sz ? -1 : vs[v-1])<<"\n";
    }

    return 0;
}


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

    template<class MUStruct>
    class LazySegmentTree{
        public:
        using Monoid=typename MUStruct::Monoid;
        using Update=typename MUStruct::Update;
        using value_t=typename Monoid::value_t;
        using update_t=typename Update::update_t;

        private:

        int N;
        std::vector<value_t> dat;
        std::vector<update_t> lazy;
        std::vector<char> flag;

        static int calcN(int n){int res=1; while(res<n) res*=2; return res;};
        void propagate(int node);
        void applyLazy(int node,update_t x);
        void applyImpl(int l,int r,int k,int lb,int ub,update_t f);
        void updateImpl(int pos,int k,int lb,int ub,value_t x);
        value_t queryImpl(int l,int r,int k,int lb,int ub);
        value_t getValue(int node){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node]) : dat[node];}

        public:
        LazySegmentTree(int N);
        void apply(int l,int r,update_t f);
        void updateALL(std::vector<value_t> x);
        void update(int pos,value_t v);
        value_t query(int a,int b);

        value_t BSquery(int k,int lb,int ub){
            if(ub<0) ub=N;
            if(k>=N-1) return lb;
            propagate(k);
            int mid=(lb+ub)/2;
            if(getValue(k*2+1)<0) return BSquery(k*2+1,lb,mid);
            assert(getValue(2*k+2));
            return BSquery(k*2+2,mid,ub);
        }
    };

    template<class MUStruct>
    LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::propagate(int node){
        if(flag[node]){
            flag[node]=false;
            applyLazy(node*2+1,lazy[node]);
            applyLazy(node*2+2,lazy[node]);
            dat[node]=Monoid::op(getValue(node*2+1),getValue(node*2+2));
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
        if(flag[node]){
            lazy[node]=Update::op(lazy[node],x);
        }
        else{
            flag[node]=true;
            lazy[node]=x;
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyImpl(int l,int r,int k,int lb,int ub,update_t x){
        if(r<=lb || ub<=l) return;
        if(l<=lb && ub<=r){
            applyLazy(k,x);
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        applyImpl(l,r,k*2+1,lb,mid,x);
        applyImpl(l,r,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateImpl(int pos,int k,int lb,int ub,value_t x){
        if(!(lb<=pos && pos<ub))return;
        if(pos==lb && pos==ub-1){
            flag[k]=false;
            dat[k]=x;
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        updateImpl(pos,k*2+1,lb,mid,x);
        updateImpl(pos,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
        if(r<=lb || ub<=l) return Monoid::E();
        if(l<=lb && ub<=r){
            return getValue(k);
        }
        propagate(k);
        int mid=(lb+ub)/2;
        value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
        value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
        return Monoid::op(lhs,rhs);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::apply(int l,int r,update_t x){
        applyImpl(l,r,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::update(int pos,value_t x){
        updateImpl(pos,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateALL(std::vector<value_t> xs){
        for(int i=0;i<xs.size();i++){
            dat[i+N-1]=xs[i];
        }
        for(int i=xs.size();i<N;i++) dat[i+N-1]=Monoid::E(),flag[i+N-1]=false;
        for(int i=N-2;i>=0;i--){
            flag[i]=false;
            value_t c1v=dat[i*2+1],c2v=dat[i*2+2];
            dat[i]=Monoid::op(c1v,c2v);
        }
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
        return queryImpl(l,r,0,0,N);
    }
};

struct MUStruct{
    struct Monoid{
        using value_t=int;
        static constexpr value_t E(){return 1e9;}
        static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    };
    struct Update{
        using update_t = int;
        static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    };
    static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
};

map<int,int> compress(vector<int> v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<int,int> res;
    for(int i=0;i<v.size();i++){
        res[v[v.size()-i-1]]=i;
    }

    return res;
}

using namespace ProconLib;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> b(m);
    for(int i=0;i<m;i++) cin>>b[i];
    int q;
    cin>>q;
    vector<int> type(q),id(q),x(q);
    for(int i=0;i<q;i++){
        cin>>type[i]>>id[i]>>x[i];
        id[i]--;
    }
    // cerr<<"#Input finished"<<endl;
    map<int,int> mp;
    {
        vector<int> tmp=a;
        tmp.insert(tmp.end(),b.begin(),b.end());
        tmp.insert(tmp.end(),x.begin(),x.end());
        mp=compress(tmp);
    }
    int sz=mp.size();
    // cerr<<"#Compressed "<<sz<<endl;
    vector<int> vs(sz);
    for(auto &e:mp){
        // cerr<<e.second<<" "<<e.first<<endl;
        vs[e.second]=e.first;
    }
    LazySegmentTree<MUStruct> seg(sz);
    for(int i=0;i<sz;i++) seg.update(i,0);
    for(int i=0;i<n;i++){
        seg.apply(mp[a[i]],sz,-1);
    }

    for(int i=0;i<m;i++){
        seg.apply(mp[b[i]],sz,1);
    }
    auto calc=[&](){
        if(seg.query(0,sz)>=0) return -1;
        else return seg.BSquery(0,0,-1);
    };
    for(int i=0;i<q;i++){
        if(type[i]==1){
            seg.apply(mp[a[id[i]]],sz,1);
            seg.apply(mp[x[i]],sz,-1);
            a[id[i]]=x[i];
        }
        else{
            seg.apply(mp[b[id[i]]],sz,-1);
            seg.apply(mp[x[i]],sz,1);
            b[id[i]]=x[i];
        }
        // cerr<<seg.query(0,3)<<endl;
        // cerr<<"#"<<seg.query(0,sz)<<endl;
        int v=calc();
        // cerr<<"#"<<v<<endl;
        cout<<(v<0 ? -1 : vs[v])<<"\n";
    }

    return 0;
}


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

    template<class MUStruct>
    class LazySegmentTree{
        public:
        using Monoid=typename MUStruct::Monoid;
        using Update=typename MUStruct::Update;
        using value_t=typename Monoid::value_t;
        using update_t=typename Update::update_t;

        private:

        int N;
        std::vector<value_t> dat;
        std::vector<update_t> lazy;
        std::vector<char> flag;

        static int calcN(int n){int res=1; while(res<n) res*=2; return res;};
        void propagate(int node);
        void applyLazy(int node,update_t x);
        void applyImpl(int l,int r,int k,int lb,int ub,update_t f);
        void updateImpl(int pos,int k,int lb,int ub,value_t x);
        value_t queryImpl(int l,int r,int k,int lb,int ub);
        value_t getValue(int node){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node]) : dat[node];}

        public:
        LazySegmentTree(int N);
        void apply(int l,int r,update_t f);
        void updateALL(std::vector<value_t> x);
        void update(int pos,value_t v);
        value_t query(int a,int b);

        value_t BSquery(int k,int lb,int ub){
            if(k>=N) return lb;
            propagate(k);
            int mid=(lb+ub)/2;
            if(getValue(2*k+1)<0) return BSquery(k*2+1,lb,mid);
            assert(getValue(2*k+2<0));
            return BSquery(k*2+2,mid,ub);
        }
    };

    template<class MUStruct>
    LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::propagate(int node){
        if(flag[node]){
            flag[node]=false;
            applyLazy(node*2+1,lazy[node]);
            applyLazy(node*2+2,lazy[node]);
            dat[node]=Monoid::op(getValue(node*2+1),getValue(node*2+2));
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
        if(flag[node]){
            lazy[node]=Update::op(lazy[node],x);
        }
        else{
            flag[node]=true;
            lazy[node]=x;
        }
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::applyImpl(int l,int r,int k,int lb,int ub,update_t x){
        if(r<=lb || ub<=l) return;
        if(l<=lb && ub<=r){
            applyLazy(k,x);
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        applyImpl(l,r,k*2+1,lb,mid,x);
        applyImpl(l,r,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateImpl(int pos,int k,int lb,int ub,value_t x){
        if(!(lb<=pos && pos<ub))return;
        if(pos==lb && pos==ub-1){
            flag[k]=false;
            dat[k]=x;
            return;
        }
        propagate(k);
        int mid=(lb+ub)/2;
        updateImpl(pos,k*2+1,lb,mid,x);
        updateImpl(pos,k*2+2,mid,ub,x);
        dat[k]=Monoid::op(getValue(k*2+1),getValue(k*2+2));
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
        if(r<=lb || ub<=l) return Monoid::E();
        if(l<=lb && ub<=r){
            return getValue(k);
        }
        propagate(k);
        int mid=(lb+ub)/2;
        value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
        value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
        return Monoid::op(lhs,rhs);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::apply(int l,int r,update_t x){
        applyImpl(l,r,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::update(int pos,value_t x){
        updateImpl(pos,0,0,N,x);
    }

    template<class MUStruct>
    void LazySegmentTree<MUStruct>::updateALL(std::vector<value_t> xs){
        for(int i=0;i<xs.size();i++){
            dat[i+N-1]=xs[i];
        }
        for(int i=xs.size();i<N;i++) dat[i+N-1]=Monoid::E(),flag[i+N-1]=false;
        for(int i=N-2;i>=0;i--){
            flag[i]=false;
            value_t c1v=dat[i*2+1],c2v=dat[i*2+2];
            dat[i]=Monoid::op(c1v,c2v);
        }
    }

    template<class MUStruct>
    typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
        return queryImpl(l,r,0,0,N);
    }
};

struct MUStruct{
    struct Monoid{
        using value_t=int;
        static constexpr value_t E(){return 0;}
        static value_t op(value_t lhs,value_t rhs){ return min(lhs,rhs);}
    };
    struct Update{
        using update_t = int;
        static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
    };
    static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u){ return v+u;}
};

map<int,int> compress(vector<int> v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    map<int,int> res;
    for(int i=0;i<v.size();i++){
        res[v[v.size()-i-1]]=i;
    }

    return res;
}

using namespace ProconLib;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> b(m);
    for(int i=0;i<m;i++) cin>>b[i];
    int q;
    cin>>q;
    vector<int> type(q),id(q),x(q);
    for(int i=0;i<q;i++){
        cin>>type[i]>>id[i]>>x[i];
        id[i]--;
    }
    // cerr<<"#Input finished"<<endl;
    map<int,int> mp;
    {
        vector<int> tmp=a;
        tmp.insert(tmp.end(),b.begin(),b.end());
        // cerr<<"#"<<endl;
        tmp.insert(tmp.end(),x.begin(),x.end());
        mp=compress(tmp);
    }
    int sz=mp.size();
    // cerr<<"#Compressed "<<sz<<endl;
    vector<int> vs(sz);
    for(auto &e:mp){
        vs[e.second]=e.first;
    }
    LazySegmentTree<MUStruct> seg(sz);
    for(int i=0;i<n;i++){
        seg.apply(mp[a[i]],sz,-1);
    }

    for(int i=0;i<m;i++){
        seg.apply(mp[b[i]],sz,1);
    }
    auto calc=[&](){
        if(seg.query(0,sz)>=0) return -1;
        else return seg.BSquery(0,0,sz);
    };
    for(int i=0;i<q;i++){
        if(type[i]==1){
            seg.apply(mp[a[id[i]]],sz,1);
            seg.apply(mp[x[i]],sz,-1);
            a[id[i]]=x[i];
        }
        else{
            seg.apply(mp[b[id[i]]],sz,-1);
            seg.apply(mp[x[i]],sz,1);
            b[id[i]]=x[i];
        }
        // cerr<<"#"<<seg.query(0,sz)<<endl;
        int v=calc();
        // cerr<<"#"<<endl;
        cout<<(v<0 ? -1 : vs[v])<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
LL n,k,c;

int main()
{
      cin>>n>>k;
      LL g=1;
      LL lcm=1;
      bool sig=0;
      for(LL i=0;i<n;i++)
      {
           scanf("%lld",&c);
           g=__gcd(g,c);
           lcm=lcm*g*c;
           lcm%=k;
           if(c==k)
              sig=1;
      }

      if(!lcm) sig=1;
      if(sig)
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
      return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
LL n,k,c;

int main()
{
      cin>>n>>k;
      LL g;
      LL lcm;
      bool sig=0;
      for(LL i=0;i<n;i++)
      {
           scanf("%lld",&c);
           if(c==k)
              sig=1;
           if(!i) { lcm=c; continue;}
           g=__gcd(lcm,c);
           lcm=(lcm*c)/g;
           lcm%=k;
      }

      if(!lcm or k==1) sig=1;
      if(sig)
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
      return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
LL n,k,c;

int main()
{
      cin>>n>>k;
      LL g=0;
      LL lcm;
      bool sig=0;
      for(LL i=0;i<n;i++)
      {
           scanf("%lld",&c);
           g=__gcd(g,c);
           lcm=(g*c)/g;
           lcm%=k;
           if(c==k)
              sig=1;
      }

      if(!lcm) sig=1;
      if(sig)
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
      return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
LL n,k,c;

int main()
{
      cin>>n>>k;
      LL g;
      LL lcm;
      bool sig=0;
      for(LL i=0;i<n;i++)
      {
           scanf("%lld",&c);
           if(!i) { lcm=c; continue;}
           g=__gcd(lcm,c);
           lcm=(lcm*c)/g;
           lcm%=k;
           if(c==k)
              sig=1;
      }

      if(!lcm) sig=1;
      if(sig)
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
      return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
LL n,k,c;

int main()
{
      cin>>n>>k;
      LL g=1;
      LL lcm=1;
      bool sig=0;
      for(LL i=0;i<n;i++)
      {
           scanf("%lld",&c);
           g=__gcd(g,c);
           lcm=g*c;
           lcm%=k;
           if(c==k)
              sig=1;
      }

      if(!lcm) sig=1;
      if(sig)
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
      return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
			if(i*i>1e6)
				break;
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it<=now;it++){
			if(now%*it==0&&k%*it==0){
				k/=*it;
				while(now%*it==0)
					now/=*it;
			}
		}
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
			if(i>1e6)break;
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it<=now;it++){
				while(now%*it==0&&k%*it==0){
					k/=*it;
					now/=*it;
				}
		}
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
			if(i*i>1e6)
				break;
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it* *it<=now;it++){
			if(now%*it==0&&k%*it==0){
				k/=*it;
			}
		}
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;i<1e6;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it<=now;it++){
				while(now%*it==0&&k%*it==0){
					k/=*it;
					now/=*it;
				}
		}
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
			if(i*i>1e6)
				break;
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it<=now;it++){
			if(now%*it==0){
				while(k%*it==0)
					k/=*it;
			}
		}
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
			if(i>1e6)break;
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	map<int,int> combin;
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it * *it<=now;it++){
			if(now%*it==0&&k%*it==0){
				int cnt=0;
				while(now%*it==0){
					cnt++;
					now/=*it;
				}
				combin[*it]=max(combin[*it],cnt);
			}
		}
		if(k%now==0)
			combin[now]=max(combin[now],1);
	}
	for(map<int,int>::iterator it=combin.begin();it!=combin.end();it++){
		for(int i=0;i<it->second&&k%it->first==0;i++){
			k/=it->first;
		}
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
			if(i>1e6)break;
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	map<int,int> combin;
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it * *it<=now;it++){
			if(now%*it==0&&k%*it==0){
				int cnt=0;
				while(now%*it==0){
					cnt++;
					now/=*it;
				}
				combin[*it]=max(combin[*it],cnt);
			}
			else{
				while(now%*it==0)
					now/=*it;
			}
		}
		if(k%now==0)
			combin[now]=max(combin[now],1);
	}
	for(map<int,int>::iterator it=combin.begin();it!=combin.end();it++){
		for(int i=0;i<it->second&&k%it->first==0;i++){
			k/=it->first;
		}
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
			if(i*i>1e6)
				break;
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it<=now;it++){
				while(now%*it==0&&k%*it==0){
					k/=*it;
					now/=*it;
				}
		}
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


/* Author haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>

#define E9 1000000000
#define INF 2147483647
#define PI 3.14159
#define ll long long
#define pii pair<int,int>

using namespace std;

int main(){
	vector<int> prime;
	prime.push_back(2);
	for(int i=3;;i+=2){
		vector<int>::iterator it;
		for(it=prime.begin();(*it)*(*it)<=i;it++){
			if(i% *it==0)
				break;
		}
		if(*it * *it>i){
			prime.push_back(i);
			if(i>1e6)break;
		}
	}
	int n,k,now=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&now);
		for(vector<int>::iterator it=prime.begin();*it * *it<=now;it++){
				while(now%*it==0&&k%*it==0){
					k/=*it;
					now/=*it;
				}
		}
		if(k%now==0)
			k/=now;
	}
	if(k==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

#ifndef ONLINE_JUDGE
//auto __redirect__ = freopen("in", "r", stdin);
#endif

#define ln '\n'
#define lsb(x) (x&-x)
#define del(x) if(x) delete x

#define rep(i,a,b) for(int i = a; i < b; ++i)
#define repq(i,a,b) for(int i = a; i <= b; ++i)

#define rev(i,a,b) for(int i = a; i >= b; --i)
#define revn(i,a,b) for(int i = a; i > b; --i)

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

int const N = 1e5 + 16;
int const M = 1e9 + 7;

int n, k;

int main() {
  scanf("%d%d", &n, &k);
  bool okay = false;
  set<int> rem;
  while(n--) {
    int c;
    scanf("%d", &c);
    if(c == k || c % k == 0 || k % c == 0) {
      okay = true;
      break;
    }
    rem.insert(c);
  }
  for(auto x : rem)
    if(k % x == 0 || x % k == 0 || x % k % k == 0) {
      okay = true;
      break;
    }

  if(okay)
    puts("Yes");
  else
    puts("No");

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

#ifndef ONLINE_JUDGE
//auto __redirect__ = freopen("in", "r", stdin);
#endif

#define ln '\n'
#define lsb(x) (x&-x)
#define del(x) if(x) delete x

#define rep(i,a,b) for(int i = a; i < b; ++i)
#define repq(i,a,b) for(int i = a; i <= b; ++i)

#define rev(i,a,b) for(int i = a; i >= b; --i)
#define revn(i,a,b) for(int i = a; i > b; --i)

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

int const N = 1e5 + 16;
int const M = 1e9 + 7;

int n, k;

int main() {
  scanf("%d%d", &n, &k);
  bool okay = false;
  while(n--) {
    int c;
    scanf("%d", &c);
    if(c == k || c % k == 0 || k % c == 0) {
      okay = true;
      break;
    }

  }

  if(okay)
    puts("Yes");
  else
    puts("No");

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

#ifndef ONLINE_JUDGE
//auto __redirect__ = freopen("in", "r", stdin);
#endif

#define ln '\n'
#define lsb(x) (x&-x)
#define del(x) if(x) delete x

#define rep(i,a,b) for(int i = a; i < b; ++i)
#define repq(i,a,b) for(int i = a; i <= b; ++i)

#define rev(i,a,b) for(int i = a; i >= b; --i)
#define revn(i,a,b) for(int i = a; i > b; --i)

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

int const N = 1e6 + 16;
int const M = 1e9 + 7;

int n, k;
int a[N];

int main() {
  scanf("%d%d", &n, &k);
  bool okay = false;
  rep(i,0,n)
    scanf("%d", a+i);

  sort(a, a+n);

  rep(i,0,n) {
    if(a[i] == k) {
      okay = true;
      break;
    }

    if(a[i] > k)
      break;

    if(a[i] < k) {
      auto x = lower_bound(a+i+1,a+n, k-a[i]);
      if(x != a+n && *x == k-a[i]) {
        okay = true;
        break;
      }
    }

  }

  if(okay)
    puts("Yes");
  else
    puts("No");

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

#ifndef ONLINE_JUDGE
//auto __redirect__ = freopen("in", "r", stdin);
#endif

#define ln '\n'
#define lsb(x) (x&-x)
#define del(x) if(x) delete x

#define rep(i,a,b) for(int i = a; i < b; ++i)
#define repq(i,a,b) for(int i = a; i <= b; ++i)

#define rev(i,a,b) for(int i = a; i >= b; --i)
#define revn(i,a,b) for(int i = a; i > b; --i)

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

int const N = 1e5 + 16;
int const M = 1e9 + 7;

int n, k;

int main() {
  scanf("%d%d", &n, &k);
  bool okay = false;
  while(n--) {
    int c;
    scanf("%d", &c);
    if(c == k) {
      okay = true;
      break;
    }

  }

  if(okay)
    puts("Yes");
  else
    puts("No");

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

#ifndef ONLINE_JUDGE
//auto __redirect__ = freopen("in", "r", stdin);
#endif

#define ln '\n'
#define lsb(x) (x&-x)
#define del(x) if(x) delete x

#define rep(i,a,b) for(int i = a; i < b; ++i)
#define repq(i,a,b) for(int i = a; i <= b; ++i)

#define rev(i,a,b) for(int i = a; i >= b; --i)
#define revn(i,a,b) for(int i = a; i > b; --i)

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

int const N = 1e5 + 16;
int const M = 1e9 + 7;

int n, k;

int main() {
  scanf("%d%d", &n, &k);
  bool okay = false;
  while(n--) {
    int c;
    scanf("%d", &c);
    if(c == k || c % k == 0 || k % c == 0) {
      okay = true;
      break;
    }

  }

  if(okay || k==1)
    puts("Yes");
  else
    puts("No");

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

#ifndef ONLINE_JUDGE
//auto __redirect__ = freopen("in", "r", stdin);
#endif

#define ln '\n'
#define lsb(x) (x&-x)
#define del(x) if(x) delete x

#define rep(i,a,b) for(int i = a; i < b; ++i)
#define repq(i,a,b) for(int i = a; i <= b; ++i)

#define rev(i,a,b) for(int i = a; i >= b; --i)
#define revn(i,a,b) for(int i = a; i > b; --i)

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

int const N = 1e5 + 16;
int const M = 1e9 + 7;

int n, k;

int main() {
  scanf("%d%d", &n, &k);
  bool okay = false;
  while(n--) {
    int c;
    scanf("%d", &c);
    if(c == k || k % c == 0) {
      okay = true;
      break;
    }

  }

  if(okay)
    puts("Yes");
  else
    puts("No");

}