#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

template<typename Monoid,typename OperatorMonoid>
struct LazySegmentTree{
    typedef function<Monoid(Monoid,Monoid)> F;
    typedef function<Monoid(Monoid,OperatorMonoid)> G;
    typedef function<OperatorMonoid(OperatorMonoid,OperatorMonoid)> H;
    int n,hi;
    F f;
    G g;
    H h;
    Monoid id0;
    OperatorMonoid id1;
    vector<Monoid> dat;
    vector<OperatorMonoid> laz;
    LazySegmentTree(int n_,F f,G g,H h,Monoid id0,OperatorMonoid id1):
                    f(f),g(g),h(h),id0(id0),id1(id1){init(n_);}
    void init(int n_){
        n=1,hi=0;
        while(n<n_) n<<=1,++hi;
        dat.assign(n<<1,id0);
        laz.assign(n<<1,id1);
    }
    void build(const vector<Monoid> &v){
        for (int i=0;i<v.size();++i) dat[i+n]=v[i];
        for (int i=n-1;i;--i) dat[i]=f(dat[i<<1|0],dat[i<<1|1]);
    }
    inline Monoid reflect(int k){
        return laz[k]==id1?dat[k]:g(dat[k],laz[k]);
    }
    inline void propagate(int k){
        if (laz[k]==id1) return;
        laz[k<<1|0]=h(laz[k<<1|0],laz[k]);
        laz[k<<1|1]=h(laz[k<<1|1],laz[k]);
        dat[k]=reflect(k);
        laz[k]=id1;
    }
    inline void thrust(int k){
        for (int i=hi;i;--i) propagate(k>>i);
    }
    inline void recalc(int k){
        while(k>>=1) dat[k]=f(reflect(k<<1|0),reflect(k<<1|1));
    }
    void update(int a,int b,OperatorMonoid x){
        if (a>=b) return;
        thrust(a+=n),thrust(b+=n-1);
        for (int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if (l&1) laz[l]=h(laz[l],x),++l;
            if (r&1) --r,laz[r]=h(laz[r],x);
        }
        recalc(a),recalc(b);
    }
    void set_val(int k,Monoid x){
        thrust(k+=n);
        dat[k]=x,laz[k]=id1;
        recalc(k);
    }
    Monoid query(int a,int b){
        if (a>=b) return id0;
        thrust(a+=n),thrust(b+=n-1);
        Monoid vl=id0,vr=id0;
        for (int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if (l&1) vl=f(vl,reflect(l++));
            if (r&1) vr=f(reflect(--r),vr);
        }
        return f(vl,vr);
    }
    // most left position p that f[a...p] meets conditin "check"
    template<typename C>
    int find_first(int a,const C &check,Monoid &M,int k,int l,int r){
        if (l+1==r){
            M=f(M,reflect(k));
            return check(M)?k-n:-1;
        }
        propagate(k);
        int m=(l+r)>>1;
        if (m<=a) return find_first(a,check,M,k<<1|1,m,r);
        if (a<=l&&!check(f(M,dat[k]))){
            M=f(M,dat[k]);
            return -1;
        }
        int vl=find_first(a,check,M,k<<1|0,l,m);
        if (~vl) return vl;
        return find_first(a,check,M,k<<1|1,m,r);
    }
    template<typename C>
    int find_first(int a,const C &check){
        Monoid M=id0;
        return find_first(a,check,M,1,0,n);
    }
    // most right position p that f[p...b) meets condition "check"
    template<typename C>
    int find_last(int b,const C &check,Monoid &M,int k,int l,int r){
        if (l+1==r){
            M=f(reflect(k),M);
            return check(M)?k-n:-1;
        }
        propagate(k);
        int m=(l+r)>>1;
        if (b<=m) return find_last(b,check,M,k<<1|0,l,m);
        if (r<=b&&!check(f(dat[k],M))){
            M=f(dat[k],M);
            return -1;
        }
        int vr=find_last(b,check,M,k<<1|1,m,r);
        if (~vr) return vr;
        return find_last(b,check,M,k<<1|0,l,m);
    }
    template<typename C>
    int find_last(int b,const C &check){
        Monoid M=id0;
        return find_last(b,check,M,1,0,n);
    }
    Monoid operator[](int i){return query(i,i+1);}
};

void CFR569_C(){
    const int MAX_A=1e6+10;
    int n,m; cin >> n >> m;
    vector<int> a(n),b(m);
    for (int i=0;i<n;++i) cin >> a[i];
    for (int i=0;i<m;++i) cin >> b[i];

    auto f=[](int a,int b){return min(a,b);};
    auto g=[](int a,int b){return a+b;};
    LazySegmentTree<int,int> seg(MAX_A,f,g,g,INF,0);
    vector<int> v(MAX_A,0);
    seg.build(v);
    for (int i=0;i<n;++i) seg.update(a[i],MAX_A,1);
    for (int i=0;i<m;++i) seg.update(b[i],MAX_A,-1);

    int q; cin >> q;
    for (;q--;){
        int t,i,x; cin >> t >> i >> x; --i;
        if (t==1){
            seg.update(a[i],MAX_A,-1);
            a[i]=x;
            seg.update(a[i],MAX_A,1);
        } else {
            seg.update(b[i],MAX_A,1);
            b[i]=x;
            seg.update(b[i],MAX_A,-1);
        }
        int ans=seg.find_last(MAX_A,[&](int x){return x<n-m;});
        cout << (ans<0?-1:ans+1) << '\n';
    }
}

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


#include <cassert>
#include <vector>

template <class monoid, class isomorphism>
class lazy_segment_tree
{
    using size_type = typename std::vector<monoid>::size_type;

    size_type orig_n, height, ext_n;
    std::vector<monoid> data;
    std::vector<isomorphism> lazy;

    void recalc(const size_type node) { data[node] = data[node << 1] + data[node << 1 | 1]; }

    void apply(size_type index, const isomorphism &iso)
    {
        data[index] *= iso;
        if(index < ext_n) lazy[index] *= iso;
    }

    void push(size_type index)
    {
        if(index < ext_n)
        {
            apply(index << 1, lazy[index]);
            apply(index << 1 | 1, lazy[index]);
            lazy[index] = isomorphism{};
        }
    }

    template <class pred_type>
    size_type left_search_subtree(size_type index, const pred_type pred, monoid mono)
    {
        assert(index);
        while(index < ext_n)
        {
            push(index);
            const monoid tmp = data[(index <<= 1) | 1] + mono;
            if(pred(tmp)) mono = tmp;
            else ++index;
        }
        return ++index -= ext_n;
    }

    template <class pred_type>
    size_type right_search_subtree(size_type index, const pred_type pred, monoid mono)
    {
        assert(index);
        while(index < ext_n)
        {
            push(index);
            const monoid tmp = mono + data[index <<= 1];
            if(pred(tmp)) ++index, mono = tmp;
        }
        return (index -= ext_n) < orig_n ? index : orig_n;
    }

public:
    lazy_segment_tree(const size_type n = 0)
        : orig_n{n}, height(orig_n > 1 ? 32 - __builtin_clz(orig_n - 1) : 0), ext_n{1u << height}, data(ext_n << 1), lazy(ext_n) {}

    lazy_segment_tree(const size_type n, const monoid &init) : lazy_segment_tree(n)
    {
        std::fill(std::next(std::begin(data), ext_n), std::end(data), init);
        for(size_type i{ext_n}; --i; ) recalc(i);
    }

    template <class iter_type, class value_type = typename std::iterator_traits<iter_type>::value_type>
    lazy_segment_tree(iter_type first, iter_type last)
        : orig_n(std::distance(first, last)), height(orig_n > 1 ? 32 - __builtin_clz(orig_n - 1) : 0), ext_n{1u << height}, data(ext_n << 1), lazy(ext_n)
    {
        static_assert(std::is_constructible<monoid, value_type>::value, "monoid(iter_type::value_type) is not constructible.");
        for(auto iter{std::next(std::begin(data), ext_n)}; iter != std::end(data) && first != last; ++iter, ++first) *iter = monoid(*first);
        for(size_type i{ext_n}; --i; ) recalc(i);
    }

    template <class container_type, typename = typename container_type::value_type>
    lazy_segment_tree(const container_type &cont) : lazy_segment_tree(std::begin(cont), std::end(cont)) {}

    // copy of the element at position i.
    typename decltype(data)::const_reference operator[](size_type i) { return fold(i, i + 1); }

    void update(size_type index, const isomorphism &iso) { update(index, index + 1, iso); }

    void update(size_type first, size_type last, const isomorphism &iso)
    {
        assert(last <= orig_n);
        if(first >= last) return;
        first += ext_n, last += ext_n - 1;
        for(size_type i = height; i; --i) push(first >> i), push(last >> i);
        for(size_type l = first, r = last + 1; last; l >>= 1, r >>= 1)
        {
            if(l < r)
            {
                if(l & 1) apply(l++, iso);
                if(r & 1) apply(--r, iso);
            }
            if(first >>= 1, last >>= 1)
            {
                recalc(first), recalc(last);
            }
        }
    }

    monoid fold() { return fold(0, orig_n); }

    monoid fold(size_type first, size_type last)
    {
        assert(last <= orig_n);
        if(first >= last) return monoid{};
        first += ext_n, last += ext_n - 1;
        monoid left_val{}, right_val{};
        for(size_type l = first, r = last + 1; last; l >>= 1, r >>= 1)
        {
            if(l < r)
            {
                if(l & 1) left_val = left_val + data[l++];
                if(r & 1) right_val = data[--r] + right_val;
            }
            if(first >>= 1, last >>= 1)
            {
                left_val *= lazy[first];
                right_val *= lazy[last];
            }
        }
        return left_val + right_val;
    }

    template <class pred_type>
    size_type left_search(size_type right, const pred_type pred)
    {
        assert(right <= orig_n);
        right += ext_n - 1;
        for(size_type i{height}; i; --i) push(right >> i);
        ++right;
        monoid mono{};
        for(size_type left{ext_n}; left != right; left >>= 1, right >>= 1)
        {
            if((left & 1) != (right & 1))
            {
                const monoid tmp = data[--right] + mono;
                if(!pred(tmp)) return left_search_subtree(right, pred, mono);
                mono = tmp;
            }
        }
        return 0;
    }

    template <class pred_type>
    size_type right_search(size_type left, const pred_type pred)
    {
        assert(left <= orig_n);
        left += ext_n;
        for(size_type i{height}; i; --i) push(left >> i);
        monoid mono{};
        for(size_type right{ext_n << 1}; left != right; left >>= 1, right >>= 1)
        {
            if((left & 1) != (right & 1))
            {
                const monoid tmp = mono + data[left];
                if(!pred(tmp)) return right_search_subtree(left, pred, mono);
                mono = tmp;
                ++left;
            }
        }
        return orig_n;
    }
}; //class lazy_segment_tree

#include <iostream>
using namespace std;

struct mino
{
    int val=1<<30;
    mino() {}
    mino(int v) : val(v) {}
    mino operator+(const mino& rhs) const
    {
        return val<rhs.val ? *this:rhs;
    }
};

struct iso
{
    int val;
    iso(int v=0) : val(v) {}
    iso &operator*=(const iso& rhs)
    {
        val+=rhs.val;
        return *this;
    }
    friend mino &operator*=(mino &lhs,iso rhs)
    {
        lhs.val+=rhs.val;
        return lhs;
    }
};

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

    lazy_segment_tree<mino,iso> laz(1<<20,0);

    int n,m; cin>>n>>m;
    vector<int> a(n),b(m);
    for(int &e: a)
    {
        cin>>e;
        laz.update(0,e,-1);
    }
    for(int &e: b)
    {
        cin>>e;
        laz.update(0,e,1);
    }

    auto pred=[&](mino x)->bool
    {
        return x.val>=0;
    };

    int Q; cin>>Q;
    while(Q--)
    {
        int k,i,x; cin>>k>>i>>x; --i;
        if(k==1)
        {
            laz.update(0,a[i],1);
            laz.update(0,x,-1);
            a[i]=x;
        }
        else
        {
            laz.update(0,b[i],-1);
            laz.update(0,x,1);
            b[i]=x;
        }
        // cout << laz.fold().val << "\n";
        auto ans=laz.left_search(1000001,pred);
        if(ans) cout << ans << "\n";
        else cout << -1 << "\n";
    }
}


#include <cassert>
#include <vector>

template <class monoid, class isomorphism>
class lazy_segment_tree
{
    using size_type = typename std::vector<monoid>::size_type;

    size_type orig_n, height, ext_n;
    std::vector<monoid> data;
    std::vector<isomorphism> lazy;

    void recalc(const size_type node) { data[node] = data[node << 1] + data[node << 1 | 1]; }

    void apply(size_type index, const isomorphism &iso)
    {
        iso.apply(data[index]);
        if(index < ext_n) lazy[index] *= iso;
    }

    void push(size_type index)
    {
        if(index >= ext_n) return;
        apply(index << 1, lazy[index]);
        apply(index << 1 | 1, lazy[index]);
        lazy[index] = isomorphism{};
    }

    template <class pred_type>
    size_type left_search_subtree(size_type index, const pred_type pred, monoid mono)
    {
        assert(index);
        while(index < ext_n)
        {
            push(index);
            const monoid tmp = data[(index <<= 1) | 1] + mono;
            if(pred(tmp)) mono = tmp;
            else ++index;
        }
        return ++index -= ext_n;
    }

    template <class pred_type>
    size_type right_search_subtree(size_type index, const pred_type pred, monoid mono)
    {
        assert(index);
        while(index < ext_n)
        {
            push(index);
            const monoid tmp = mono + data[index <<= 1];
            if(pred(tmp)) ++index, mono = tmp;
        }
        return (index -= ext_n) < orig_n ? index : orig_n;
    }

public:
    lazy_segment_tree(const size_type n = 0)
        : orig_n{n}, height(orig_n > 1 ? 32 - __builtin_clz(orig_n - 1) : 0), ext_n{1u << height}, data(ext_n << 1), lazy(ext_n) {}

    lazy_segment_tree(const size_type n, const monoid &init) : lazy_segment_tree(n)
    {
        std::fill(std::next(std::begin(data), ext_n), std::end(data), init);
        for(size_type i{ext_n}; --i; ) recalc(i);
    }

    template <class iter_type, class value_type = typename std::iterator_traits<iter_type>::value_type>
    lazy_segment_tree(iter_type first, iter_type last)
        : orig_n(std::distance(first, last)), height(orig_n > 1 ? 32 - __builtin_clz(orig_n - 1) : 0), ext_n{1u << height}, data(ext_n << 1), lazy(ext_n)
    {
        static_assert(std::is_constructible<monoid, value_type>::value, "monoid(iter_type::value_type) is not constructible.");
        for(auto iter{std::next(std::begin(data), ext_n)}; iter != std::end(data) && first != last; ++iter, ++first) *iter = monoid(*first);
        for(size_type i{ext_n}; --i; ) recalc(i);
    }

    template <class container_type, typename = typename container_type::value_type>
    lazy_segment_tree(const container_type &cont) : lazy_segment_tree(std::begin(cont), std::end(cont)) {}

    // copy of the element at position i.
    typename decltype(data)::const_reference operator[](size_type i) { return fold(i, i + 1); }

    void update(size_type index, const isomorphism &iso) { update(index, index + 1, iso); }

    void update(size_type first, size_type last, const isomorphism &iso)
    {
        assert(last <= orig_n);
        if(first >= last) return;
        first += ext_n, last += ext_n - 1;
        for(size_type i = height; i; --i) push(first >> i), push(last >> i);
        for(size_type l = first, r = last + 1; last; l >>= 1, r >>= 1)
        {
            if(l < r)
            {
                if(l & 1) apply(l++, iso);
                if(r & 1) apply(--r, iso);
            }
            if(first >>= 1, last >>= 1)
            {
                recalc(first), recalc(last);
            }
        }
    }

    monoid fold() { return fold(0, orig_n); }

    monoid fold(size_type first, size_type last)
    {
        assert(last <= orig_n);
        if(first >= last) return monoid{};
        first += ext_n, last += ext_n - 1;
        monoid left_val{}, right_val{};
        for(size_type l = first, r = last + 1; last; l >>= 1, r >>= 1)
        {
            if(l < r)
            {
                if(l & 1) left_val = left_val + data[l++];
                if(r & 1) right_val = data[--r] + right_val;
            }
            if(first >>= 1, last >>= 1)
            {
                lazy[first].apply(left_val);
                lazy[last].apply(right_val);
            }
        }
        return left_val + right_val;
    }

    template <class pred_type>
    size_type left_search(size_type right, const pred_type pred)
    {
        assert(right <= orig_n);
        right += ext_n - 1;
        for(size_type i{height}; i; --i) push(right >> i);
        ++right;
        monoid mono{};
        for(size_type left{ext_n}; left != right; left >>= 1, right >>= 1)
        {
            if((left & 1) != (right & 1))
            {
                const monoid tmp = data[--right] + mono;
                if(!pred(tmp)) return left_search_subtree(right, pred, mono);
                mono = tmp;
            }
        }
        return 0;
    }

    template <class pred_type>
    size_type right_search(size_type left, const pred_type pred)
    {
        assert(left <= orig_n);
        left += ext_n;
        for(size_type i{height}; i; --i) push(left >> i);
        monoid mono{};
        for(size_type right{ext_n << 1}; left != right; left >>= 1, right >>= 1)
        {
            if((left & 1) != (right & 1))
            {
                const monoid tmp = mono + data[left];
                if(!pred(tmp)) return right_search_subtree(left, pred, mono);
                mono = tmp;
                ++left;
            }
        }
        return orig_n;
    }
}; //class lazy_segment_tree

#include <iostream>
using namespace std;

struct mino
{
    int val=1<<30;
    mino() {}
    mino(int v) : val(v) {}
    mino operator+(const mino& rhs) const
    {
        return val<rhs.val ? *this:rhs;
    }
};

struct iso
{
    int val;
    iso(int v=0) : val(v) {}
    iso &operator*=(const iso& rhs)
    {
        val+=rhs.val;
        return *this;
    }
    void apply(mino& rhs) const
    {
        rhs.val+=val;
    }
};

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

    lazy_segment_tree<mino,iso> laz(1000000,0);

    int n,m; cin>>n>>m;
    vector<int> a(n),b(m);
    for(int &e: a)
    {
        cin>>e;
        laz.update(0,e,-1);
    }
    for(int &e: b)
    {
        cin>>e;
        laz.update(0,e,1);
    }

    auto pred=[&](mino x)->bool
    {
        return x.val>=0;
    };

    int Q; cin>>Q;
    while(Q--)
    {
        int k,i,x; cin>>k>>i>>x; --i;
        if(k==1)
        {
            laz.update(0,a[i],1);
            laz.update(0,x,-1);
            a[i]=x;
        }
        else
        {
            laz.update(0,b[i],-1);
            laz.update(0,x,1);
            b[i]=x;
        }
        // cout << laz.fold().val << "\n";
        auto ans=laz.left_search(1000000,pred);
        if(ans) cout << ans << "\n";
        else cout << -1 << "\n";
    }
}


/*
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 3e6 + 10, S = 4 * N + 10;

int n, m;
int a[N], b[N];
int sg_tree[S], lazy[S];

void test_case();
void update(int tv, int tl, int tr, int ql, int qr, int val);
int get(int tv, int tl, int tr);
void push(int tv, int lc, int rc);

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		update(1, 1, N, 1, a[i], 1);
	}
	for (int i = 1; i <= m; ++i) {
		cin >> b[i];
		update(1, 1, N, 1, b[i], -1);
	}
	int q;
	cin >> q;
	while (q--) {
		int typ, i, x;
		cin >> typ >> i >> x;
		if (typ == 1) {
			update(1, 1, N, 1, a[i], -1);
			a[i] = x;
			update(1, 1, N, 1, a[i], 1);
		} else {
			update(1, 1, N, 1, b[i], 1);
			b[i] = x;
			update(1, 1, N, 1, b[i], -1);
		}
		cout << get(1, 1, N) << "\n";
	}
}

void update(int tv, int tl, int tr, int ql, int qr, int val) {
	if (qr < tl || ql > tr) {
		return;
	} else if (ql <= tl && tr <= qr) {
		sg_tree[tv] += val;
		lazy[tv] += val;
	} else {
		int tm = tl + tr >> 1, lc = 2 * tv, rc = lc + 1;
		push(tv, lc, rc);
		update(lc, tl, tm, ql, qr, val);
		update(rc, tm + 1, tr, ql, qr, val);
		sg_tree[tv] = max(sg_tree[lc], sg_tree[rc]);
	}
}

int get(int tv, int tl, int tr) {
	if (sg_tree[tv] <= 0) {
		return -1;
	} else if (tl == tr) {
		return tl;
	} else {
		int tm = tl + tr >> 1, lc = 2 * tv, rc = lc + 1;
		push(tv, lc, rc);
		if (sg_tree[rc] > 0) {
			return get(rc, tm + 1, tr);
		} else {
			return get(lc, tl, tm);
		}
	}
}

void push(int tv, int lc, int rc) {
	sg_tree[lc] += lazy[tv];
	lazy[lc] += lazy[tv];
	sg_tree[rc] += lazy[tv];
	lazy[rc] += lazy[tv];
	lazy[tv] = 0;
}


/*
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e6 + 10, S = 4 * N + 10;

int n, m;
int a[N], b[N];
int sg_tree[S], lazy[S];

void test_case();
void update(int tv, int tl, int tr, int ql, int qr, int val);
int get(int tv, int tl, int tr);
void push(int tv, int lc, int rc);

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		update(1, 1, N, 1, a[i], 1);
	}
	for (int i = 1; i <= m; ++i) {
		cin >> b[i];
		update(1, 1, N, 1, b[i], -1);
	}
	int q;
	cin >> q;
	while (q--) {
		int typ, i, x;
		cin >> typ >> i >> x;
		if (typ == 1) {
			update(1, 1, N, 1, a[i], -1);
			a[i] = x;
			update(1, 1, N, 1, a[i], 1);
		} else {
			update(1, 1, N, 1, b[i], 1);
			b[i] = x;
			update(1, 1, N, 1, b[i], -1);
		}
		cout << get(1, 1, N) << "\n";
	}
}

void update(int tv, int tl, int tr, int ql, int qr, int val) {
	if (qr < tl || ql > tr) {
		return;
	} else if (ql <= tl && tr <= qr) {
		sg_tree[tv] += val;
		lazy[tv] += val;
	} else {
		int tm = tl + tr >> 1, lc = 2 * tv, rc = lc + 1;
		push(tv, lc, rc);
		update(lc, tl, tm, ql, qr, val);
		update(rc, tm + 1, tr, ql, qr, val);
		sg_tree[tv] = max(sg_tree[lc], sg_tree[rc]);
	}
}

int get(int tv, int tl, int tr) {
	if (sg_tree[tv] <= 0) {
		return -1;
	} else if (tl == tr) {
		return tl;
	} else {
		int tm = tl + tr >> 1, lc = 2 * tv, rc = lc + 1;
		push(tv, lc, rc);
		if (sg_tree[rc] > 0) {
			return get(rc, tm + 1, tr);
		} else {
			return get(lc, tl, tm);
		}
	}
}

void push(int tv, int lc, int rc) {
	sg_tree[lc] += lazy[tv];
	lazy[lc] += lazy[tv];
	sg_tree[rc] += lazy[tv];
	lazy[rc] += lazy[tv];
	lazy[tv] = 0;
}


/*
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 3e5 + 10, S = 4 * N + 10;

int n, m;
int a[N], b[N];
int sg_tree[S], lazy[S];

void test_case();
void update(int tv, int tl, int tr, int ql, int qr, int val);
int get(int tv, int tl, int tr);
void push(int tv, int lc, int rc);

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		update(1, 1, N, 1, a[i], 1);
	}
	for (int i = 1; i <= m; ++i) {
		cin >> b[i];
		update(1, 1, N, 1, b[i], -1);
	}
	int q;
	cin >> q;
	while (q--) {
		int typ, i, x;
		cin >> typ >> i >> x;
		if (typ == 1) {
			update(1, 1, N, 1, a[i], -1);
			a[i] = x;
			update(1, 1, N, 1, a[i], 1);
		} else {
			update(1, 1, N, 1, b[i], 1);
			b[i] = x;
			update(1, 1, N, 1, b[i], -1);
		}
		cout << get(1, 1, N) << "\n";
	}
}

void update(int tv, int tl, int tr, int ql, int qr, int val) {
	if (qr < tl || ql > tr) {
		return;
	} else if (ql <= tl && tr <= qr) {
		sg_tree[tv] += val;
		lazy[tv] += val;
	} else {
		int tm = tl + tr >> 1, lc = 2 * tv, rc = lc + 1;
		push(tv, lc, rc);
		update(lc, tl, tm, ql, qr, val);
		update(rc, tm + 1, tr, ql, qr, val);
		sg_tree[tv] = max(sg_tree[lc], sg_tree[rc]);
	}
}

int get(int tv, int tl, int tr) {
	if (sg_tree[tv] <= 0) {
		return -1;
	} else if (tl == tr) {
		return tl;
	} else {
		int tm = tl + tr >> 1, lc = 2 * tv, rc = lc + 1;
		push(tv, lc, rc);
		if (sg_tree[rc] > 0) {
			return get(rc, tm + 1, tr);
		} else {
			return get(lc, tl, tm);
		}
	}
}

void push(int tv, int lc, int rc) {
	sg_tree[lc] += lazy[tv];
	lazy[lc] += lazy[tv];
	sg_tree[rc] += lazy[tv];
	lazy[rc] += lazy[tv];
	lazy[tv] = 0;
}


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

typedef int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
//#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e6,mod=1e9+7,bit=61;

ll a[300001],b[300001];
vector<ll> suff(N+1,0);

template<typename T>
class segment
{
    public:
        int n;
        vector<T> st;
        vector<bool> isleft;
        vector<int> lazy;
        vector<int> a;

        segment() {}

        segment(int _n,vector<int> &_a)
        {
            n=_n;
            st.resize(4*n+10);
            isleft.resize(4*n+10,0);
            lazy.resize(4*n+10,0);
            a=_a;
        }

        T merge(T &a,T &b)
        {
            T res=max(a,b);
            return res;
        }

        void propagate(int si,int l,int r)
        {
            if(l!=r)
            {
                isleft[2*si]=1;
                isleft[2*si+1]=1;
                lazy[2*si]+=lazy[si];
                lazy[2*si+1]+=lazy[si];
            }
            st[si]+=lazy[si];
            lazy[si]=0;
            isleft[si]=0;
        }

        void create(int si,int l,int r)
        {
            if(l==r)
            {
                st[si]=a[l];
                return;
            }
            int mid=(l+r)>>1;
            create(2*si,l,mid);
            create(2*si+1,mid+1,r);
            st[si]=merge(st[2*si],st[2*si+1]);
        }

        void update(int si,int l,int r,int ql,int qr,int val)
        {
            if(isleft[si])
            {
                propagate(si,l,r);
            }
            if(ql>r or qr<l or l>r)
            {
                return;
            }
            if(ql<=l and qr>=r)
            {
                isleft[si]=1;
                lazy[si]+=val;
                propagate(si,l,r);
                return;
            }
            int mid=(l+r)>>1;
            update(2*si,l,mid,ql,qr,val);
            update(2*si+1,mid+1,r,ql,qr,val);
            st[si]=merge(st[2*si],st[2*si+1]);
        }

        T query(int si,int l,int r,int ql,int qr)
        {
            if(isleft[si])
            {
                propagate(si,l,r);
            }
            if(ql>r or qr<l or l>r)
            {
                return -inf;
            }
            if(ql<=l and qr>=r)
            {
                return st[si];
            }
            int mid=(l+r)>>1;
            T ansl=query(2*si,l,mid,ql,qr);
            T ansr=query(2*si+1,mid+1,r,ql,qr);
            T ans=merge(ansl,ansr);
            return ans;
        }
};

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        f(i,1,n)
        {
            cin>>a[i];
            suff[a[i]]++;
        }
        f(i,1,m)
        {
            cin>>b[i];
            suff[b[i]]--;
        }
        rf(i,N-1,1)
        {
            suff[i]+=suff[i+1];
        }
        segment<ll> obj(N,suff);
        obj.create(1,1,N);
        ll q;
        cin>>q;
        while(q--)
        {
            ll tp,i,x;
            cin>>tp>>i>>x;
            if(tp==1)
            {
                obj.update(1,1,N,1,a[i],-1);
                a[i]=x;
                obj.update(1,1,N,1,a[i],1);
            }
            else
            {
                obj.update(1,1,N,1,b[i],1);
                b[i]=x;
                obj.update(1,1,N,1,b[i],-1);
            }
            ll l=1,r=N,ans=-1;
            while(l<=r)
            {
                ll mid=(l+r)>>1;
                if(obj.query(1,1,N,mid,N)>0)
                {
                    ans=mid;
                    l=mid+1;
                }
                else
                {
                    r=mid-1;
                }
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e6,mod=1e9+7,bit=61;

template<typename T>
class segment
{
    public:
        int n;
        vector<T> st;
        vector<bool> isleft;
        vector<long long> lazy;
        vector<long long> a;

        segment() {}

        segment(int _n,vector<long long> &_a)
        {
            n=_n;
            st.resize(4*n+10);
            isleft.resize(4*n+10,0);
            lazy.resize(4*n+10,0);
            a=_a;
        }

        T merge(T &a,T &b)
        {
            T res=max(a,b);
            return res;
        }

        void propagate(int si,int l,int r)
        {
            if(l!=r)
            {
                isleft[2*si]=1;
                isleft[2*si+1]=1;
                lazy[2*si]+=lazy[si];
                lazy[2*si+1]+=lazy[si];
            }
            st[si]+=lazy[si];
            lazy[si]=0;
            isleft[si]=0;
        }

        void create(int si,int l,int r)
        {
            if(l==r)
            {
                st[si]=a[l];
                return;
            }
            int mid=(l+r)>>1;
            create(2*si,l,mid);
            create(2*si+1,mid+1,r);
            st[si]=merge(st[2*si],st[2*si+1]);
        }

        void update(int si,int l,int r,int ql,int qr,int val)
        {
            if(isleft[si])
            {
                propagate(si,l,r);
            }
            if(ql>r or qr<l or l>r)
            {
                return;
            }
            if(ql<=l and qr>=r)
            {
                isleft[si]=1;
                lazy[si]+=val;
                propagate(si,l,r);
                return;
            }
            int mid=(l+r)>>1;
            update(2*si,l,mid,ql,qr,val);
            update(2*si+1,mid+1,r,ql,qr,val);
            st[si]=merge(st[2*si],st[2*si+1]);
        }

        T query(int si,int l,int r,int ql,int qr)
        {
            if(isleft[si])
            {
                propagate(si,l,r);
            }
            if(ql>r or qr<l or l>r)
            {
                return -inf;
            }
            if(ql<=l and qr>=r)
            {
                return st[si];
            }
            int mid=(l+r)>>1;
            T ansl=query(2*si,l,mid,ql,qr);
            T ansr=query(2*si+1,mid+1,r,ql,qr);
            T ans=merge(ansl,ansr);
            return ans;
        }
};

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        vector<ll> suff(N+1,0);
        ll n,m;
        cin>>n>>m;
        ll a[n+1];
        ll b[m+1];
        f(i,1,n)
        {
            cin>>a[i];
            suff[a[i]]++;
        }
        f(i,1,m)
        {
            cin>>b[i];
            suff[b[i]]--;
        }
        rf(i,N-1,1)
        {
            suff[i]+=suff[i+1];
        }
        segment<ll> obj(N,suff);
        obj.create(1,1,N);
        ll q;
        cin>>q;
        while(q--)
        {
            ll tp,i,x;
            cin>>tp>>i>>x;
            if(tp==1)
            {
                obj.update(1,1,N,1,a[i],-1);
                a[i]=x;
                obj.update(1,1,N,1,a[i],1);
            }
            else
            {
                obj.update(1,1,N,1,b[i],1);
                b[i]=x;
                obj.update(1,1,N,1,b[i],-1);
            }
            ll l=1,r=N,ans=-1;
            while(l<=r)
            {
                ll mid=(l+r)>>1;
                if(obj.query(1,1,N,mid,N)>0)
                {
                    ans=mid;
                    l=mid+1;
                }
                else
                {
                    r=mid-1;
                }
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


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

struct node
{
    int l, r, val, lazy;
    node *lnode, *rnode;

    node(int l, int r) : l(l), r(r), val(0), lazy(0)
    {
        if (r - l == 1)
        {
            lnode = NULL;
            rnode = NULL;
        }
        else
        {
            lnode = new node(l, l + r >> 1);
            rnode = new node(l + r >> 1, r);
        }
    }

    void propagate()
    {
        if (r - l != 1)
        {
            lnode->lazy += lazy;
            rnode->lazy += lazy;
        }

        val += lazy;
        lazy = 0;
    }

    void update(int i, int delta)
    {
        if (l >= i)
            propagate();
        else if (r > i)
        {
            propagate();
            lnode->update(i, delta);
            rnode->update(i, delta);
            val = max(lnode->val, rnode->val);
        }
        else
        {
            lazy += delta;
            propagate();
        }
    }

    int query()
    {
        if (val <= 0)
            return -1;

        if (r - l == 1)
            return r;

        lnode->propagate();
        rnode->propagate();

        if (rnode->val > 0)
            return rnode->query();
        else
            return lnode->query();
    }
};

node* tree = new node(0, 1000000);

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

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

    int price[n];
    int money[m];

    for (int i = 0; i != n; ++i)
    {
        int x;
        cin >> x;
        price[i] = x;
        tree->update(x, 1);
    }
    for (int i = 0; i != m; ++i)
    {
        int x;
        cin >> x;
        money[i] = x;
        tree->update(x, -1);
    }

    int q;
    for (cin >> q; q--;)
    {
        int t, i, x;
        cin >> t >> i >> x;
        --i;

        if (t == 1)
        {
            tree->update(price[i], -1);
            price[i] = x;
            tree->update(price[i], 1);
        }
        else
        {
            tree->update(money[i], 1);
            money[i] = x;
            tree->update(money[i], -1);
        }

        tree->propagate();
        cout << tree->query() << '\n';
    }

    return 0;
}


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

struct node
{
    int l, r, val, lazy;
    node *lnode, *rnode;

    node(int l, int r) : l(l), r(r), val(0), lazy(0)
    {
        if (r - l == 1)
        {
            lnode = NULL;
            rnode = NULL;
        }
        else
        {
            lnode = new node(l, l + r >> 1);
            rnode = new node(l + r >> 1, r);
        }
    }

    void propagate()
    {
        if (r - l != 1)
        {
            lnode->lazy += lazy;
            rnode->lazy += lazy;
        }

        val += lazy;
        lazy = 0;
    }

    void update(int i, int delta)
    {
        propagate();

        if (l >= i)
            return;
        else if (r > i)
        {
            lnode->update(i, delta);
            rnode->update(i, delta);
            val = max(lnode->val, rnode->val);
        }
        else
        {
            lazy += delta;
            propagate();
        }
    }

    int query()
    {
        if (val <= 0)
            return -1;

        if (r - l == 1)
            return r;

        lnode->propagate();
        rnode->propagate();

        if (rnode->val > 0)
            return rnode->query();
        else if (lnode->val > 0)
            return lnode->query();

        assert(false);
    }
};

node* tree = new node(0, 10);

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

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

    int price[n];
    int money[m];

    for (int i = 0; i != n; ++i)
    {
        int x;
        cin >> x;
        price[i] = x;
        tree->update(x, 1);
        // cout << x << '\n';
        // cout << tree->val << '\n';
        // cout << '\n';
    }
    for (int i = 0; i != m; ++i)
    {
        int x;
        cin >> x;
        money[i] = x;
        tree->update(x, -1);
        // cout << x << '\n';
        // cout << tree->rnode->val << '\n';
        // cout << tree->val << '\n';
        // cout << '\n';
    }

    // cout << '\n';
    // cout << tree->val << '\n';
    // cout << '\n';

    int q;
    for (cin >> q; q--;)
    {
        int t, i, x;
        cin >> t >> i >> x;
        --i;

        if (t == 1)
        {
            tree->update(price[i], -1);
            price[i] = x;
            tree->update(price[i], 1);
        }
        else
        {
            tree->update(money[i], 1);
            money[i] = x;
            tree->update(money[i], -1);
        }

        tree->propagate();
        cout << tree->query() << '\n';
        // cout << '\n';
        // cout << tree->val << '\n';
        // cout << tree->lnode->val << '\n';
        // cout << tree->lnode->val << '\n';
    }

    return 0;
}


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

struct node
{
    int l, r, val, lazy;
    node *lnode, *rnode;

    node(int l, int r) : l(l), r(r), val(0), lazy(0)
    {
        if (r - l == 1)
        {
            lnode = NULL;
            rnode = NULL;
        }
        else
        {
            lnode = new node(l, l + r >> 1);
            rnode = new node(l + r >> 1, r);
        }
    }

    void propagate()
    {
        if (r - l != 1)
        {
            lnode->lazy += lazy;
            rnode->lazy += lazy;
        }

        val += lazy;
        lazy = 0;
    }

    void update(int i, int delta)
    {
        if (l >= i)
            return;
        else if (r > i)
        {
            propagate();
            lnode->update(i, delta);
            rnode->update(i, delta);
            val = max(lnode->val, rnode->val);
        }
        else
        {
            lazy += delta;
            propagate();
        }
    }

    int query()
    {
        if (val <= 0)
            return -1;

        if (r - l == 1)
            return r;

        lnode->propagate();
        rnode->propagate();

        if (rnode->val > 0)
            return rnode->query();
        else if (lnode->val > 0)
            return lnode->query();

        assert(false);
    }
};

node* tree = new node(0, 1000000);

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

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

    int price[n];
    int money[m];

    for (int i = 0; i != n; ++i)
    {
        int x;
        cin >> x;
        price[i] = x;
        tree->update(x, 1);
    }
    for (int i = 0; i != m; ++i)
    {
        int x;
        cin >> x;
        money[i] = x;
        tree->update(x, -1);
    }

    int q;
    for (cin >> q; q--;)
    {
        int t, i, x;
        cin >> t >> i >> x;
        --i;

        if (t == 1)
        {
            tree->update(price[i], -1);
            price[i] = x;
            tree->update(price[i], 1);
        }
        else
        {
            tree->update(money[i], 1);
            money[i] = x;
            tree->update(money[i], -1);
        }

        tree->propagate();
        cout << tree->query() << '\n';
        // cout << tree->val << '\n';
        // cout << tree->lnode->val << '\n';
        // cout << tree->lnode->val << '\n';
        // cout << '\n';
    }

    return 0;
}


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

struct node
{
    int l, r, val, lazy;
    node *lnode, *rnode;

    node(int l, int r) : l(l), r(r), val(0), lazy(0)
    {
        if (r - l == 1)
        {
            lnode = NULL;
            rnode = NULL;
        }
        else
        {
            lnode = new node(l, l + r >> 1);
            rnode = new node(l + r >> 1, r);
        }
    }

    void propagate()
    {
        if (r - l != 1)
        {
            lnode->lazy += lazy;
            rnode->lazy += lazy;
        }

        val += lazy;
        lazy = 0;
    }

    void update(int i, int delta)
    {
        propagate();

        if (l >= i)
            return;
        else if (r > i)
        {
            lnode->update(i, delta);
            rnode->update(i, delta);
            val = max(lnode->val, rnode->val);
        }
        else
        {
            lazy += delta;
            propagate();
        }
    }

    int query()
    {
        if (val <= 0)
            return -1;

        if (r - l == 1)
            return r;

        lnode->propagate();
        rnode->propagate();

        if (rnode->val > 0)
            return rnode->query();
        else if (lnode->val > 0)
            return lnode->query();

        assert(false);
    }
};

node* tree = new node(0, 1000000);

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

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

    int price[n];
    int money[m];

    for (int i = 0; i != n; ++i)
    {
        int x;
        cin >> x;
        price[i] = x;
        tree->update(x, 1);
        // cout << x << '\n';
        // cout << tree->val << '\n';
        // cout << '\n';
    }
    for (int i = 0; i != m; ++i)
    {
        int x;
        cin >> x;
        money[i] = x;
        tree->update(x, -1);
        // cout << x << '\n';
        // cout << tree->rnode->val << '\n';
        // cout << tree->val << '\n';
        // cout << '\n';
    }

    // cout << '\n';
    // cout << tree->val << '\n';
    // cout << '\n';

    int q;
    for (cin >> q; q--;)
    {
        int t, i, x;
        cin >> t >> i >> x;
        --i;

        if (t == 1)
        {
            tree->update(price[i], -1);
            price[i] = x;
            tree->update(price[i], 1);
        }
        else
        {
            tree->update(money[i], 1);
            money[i] = x;
            tree->update(money[i], -1);
        }

        tree->propagate();
        cout << tree->query() << '\n';
        // cout << '\n';
        // cout << tree->val << '\n';
        // cout << tree->lnode->val << '\n';
        // cout << tree->lnode->val << '\n';
    }

    return 0;
}


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

struct node
{
    int l, r, val, lazy;
    node *lnode, *rnode;

    node(int l, int r) : l(l), r(r), val(0), lazy(0)
    {
        if (r - l == 1)
        {
            lnode = NULL;
            rnode = NULL;
        }
        else
        {
            lnode = new node(l, l + r >> 1);
            rnode = new node(l + r >> 1, r);
        }
    }

    void propagate()
    {
        if (r - l != 1)
        {
            lnode->lazy += lazy;
            rnode->lazy += lazy;
        }

        val += lazy;
        lazy = 0;
    }

    void update(int i, int delta)
    {
        if (l >= i)
            return;
        else if (r > i)
        {
            propagate();
            lnode->update(i, delta);
            rnode->update(i, delta);
            val = max(lnode->val, rnode->val);
        }
        else
        {
            lazy += delta;
            propagate();
        }
    }

    int query()
    {
        if (val <= 0)
            return -1;

        if (r - l == 1)
            return r;

        lnode->propagate();
        rnode->propagate();

        if (rnode->val > 0)
            return rnode->query();
        else if (lnode->val > 0)
            return lnode->query();
    }
};

node* tree = new node(0, 1000000);

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

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

    int price[n];
    int money[m];

    for (int i = 0; i != n; ++i)
    {
        int x;
        cin >> x;
        price[i] = x;
        tree->update(x, 1);
    }
    for (int i = 0; i != m; ++i)
    {
        int x;
        cin >> x;
        money[i] = x;
        tree->update(x, -1);
    }

    int q;
    for (cin >> q; q--;)
    {
        int t, i, x;
        cin >> t >> i >> x;
        --i;

        if (t == 1)
        {
            tree->update(price[i], -1);
            price[i] = x;
            tree->update(price[i], 1);
        }
        else
        {
            tree->update(money[i], 1);
            money[i] = x;
            tree->update(money[i], -1);
        }

        tree->propagate();
        cout << tree->query() << '\n';
        // cout << tree->val << '\n';
        // cout << tree->lnode->val << '\n';
        // cout << tree->lnode->val << '\n';
        // cout << '\n';
    }

    return 0;
}


#include <iostream>
#include <vector>

constexpr int M = 1e6;

struct Tree {
	int n;
	std::vector<int> max;
	std::vector<int> lazy;
	Tree(int n) : n(n), max(n * 4), lazy(n * 4) {}
	void push(int s) {
		apply(s * 2, lazy[s]);
		apply(s * 2 + 1, lazy[s]);
		lazy[s] = 0;
	}
	void apply(int s, int k) {
		max[s] += k;
		lazy[s] += k;
	}
	void pull(int s) {
		max[s] = std::max(max[s * 2], max[s * 2 + 1]);
	}
	void change(int l, int r, int k, int x, int y, int s) {
		if (r <= x || y <= l) return;
		if (l <= x && y <= r) apply(s, k);
		else {
			push(s);
			int m = (x + y) / 2;
			change(l, r, k, x, m, s * 2);
			change(l, r, k, m, y, s * 2 + 1);
			pull(s);
		}
	}
	int find_last(int x, int y, int s) {
		if (y - x == 1) return x;
		push(s);
		int m = (x + y) / 2;
		if (max[s * 2 + 1] > 0) return find_last(m, y, s * 2 + 1);
		else return find_last(x, m, s * 2);
	}
	void change(int l, int r, int k) {
		change(l, r, k, 0, n, 1);
	}
	int find_last() {
		return find_last(0, n, 1);
	}
} tree(M);

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, m;
	std::cin >> n >> m;
	std::vector<int> a(n), b(m);
	for (auto& x : a) {
		std::cin >> x;
		tree.change(0, x, +1);
	}
	for (auto& x : b) {
		std::cin >> x;
		tree.change(0, x, -1);
	}
	int q;
	std::cin >> q;
	while (q--) {
		int t, i, x;
		std::cin >> t >> i >> x;
		--i;
		if (t == 1) {
			tree.change(0, a[i], -1);
			a[i] = x;
			tree.change(0, a[i], +1);
		} else {
			tree.change(0, b[i], +1);
			b[i] = x;
			tree.change(0, b[i], -1);
		}
		std::cout << (tree.max[1] <= 0 ? -1 : tree.find_last() + 1) << '\n';
	}
}


#include <iostream>
#include <vector>
using namespace std;
struct Tree {
	int n;
	vector<int> p;
	vector<int> lz;
	Tree(int n) : n(n), p(n * 4), lz(n * 4) {}
	void push(int s) {
		if (!lz[s])
			return;
		apply(s * 2, lz[s]);
		apply(s * 2 + 1, lz[s]);
		lz[s] = 0;
	}
	void apply(int s, int k) {
		p[s] += k;
		lz[s] += k;
	}
	void change(int l, int r, int k, int x, int y, int s) {
		if (r <= x || y <= l)
			return;
		if (l <= x && y <= r) {
			apply(s, k);
		} else {
			push(s);
			int m = (x + y) / 2;
			change(l, r, k, x, m, s * 2);
			change(l, r, k, m, y, s * 2 + 1);
			p[s] = max(p[s * 2], p[s * 2 + 1]);
		}
	}
	int find_last(int x, int y, int s) {
		if (y - x == 1)
			return x;
		push(s);
		int m = (x + y) / 2;
		return p[s * 2 + 1] > 0 ? find_last(m, y, s * 2 + 1) : find_last(x, m, s * 2);
	}
	void change(int l, int r, int k) {
		change(l, r, k, 0, n, 1);
	}
	int find_last() {
		return find_last(0, n, 1);
	}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	const int mx = 1e6;
	Tree tree(mx);
	vector<int> a(n), b(m);
	for (auto& x : a) {
		cin >> x;
		tree.change(0, x, 1);
	}
	for (auto& x : b) {
		cin >> x;
		tree.change(0, x, -1);
	}
	int q;
	cin >> q;
	while (q--) {
		int t, i, x;
		cin >> t >> i >> x;
		--i;
		if (t == 1) {
			tree.change(0, a[i], -1);
			a[i] = x;
			tree.change(0, a[i], 1);
		} else {
			tree.change(0, b[i], 1);
			b[i] = x;
			tree.change(0, b[i], -1);
		}
		cout << (tree.p[1] <= 0 ? -1 : tree.find_last() + 1) << '\n';
	}
}


#include <iostream>
#include <vector>
using namespace std;
struct Tree {
	int n;
	vector<int> p;
	vector<int> lz;
	Tree(int n) : n(n), p(n * 4), lz(n * 4) {}
	void push(int s) {
		apply(s * 2, lz[s]);
		apply(s * 2 + 1, lz[s]);
		lz[s] = 0;
	}
	void apply(int s, int k) {
		p[s] += k;
		lz[s] += k;
	}
	void change(int l, int r, int k, int x, int y, int s) {
		if (r <= x || y <= l) return;
		if (l <= x && y <= r) apply(s, k);
		else {
			push(s);
			int m = (x + y) / 2;
			change(l, r, k, x, m, s * 2);
			change(l, r, k, m, y, s * 2 + 1);
			p[s] = max(p[s * 2], p[s * 2 + 1]);
		}
	}
	int find_last(int x, int y, int s) {
		if (y - x == 1) return x;
		push(s);
		int m = (x + y) / 2;
		if (p[s * 2 + 1] > 0) return find_last(m, y, s * 2 + 1);
		else return find_last(x, m, s * 2);
	}
	void change(int l, int r, int k) {
		change(l, r, k, 0, n, 1);
	}
	int find_last() {
		return find_last(0, n, 1);
	}
};
const int mx = 1e6;
Tree tree(mx);
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	for (auto& x : a) {
		cin >> x;
		tree.change(0, x, +1);
	}
	for (auto& x : b) {
		cin >> x;
		tree.change(0, x, -1);
	}
	int q;
	cin >> q;
	while (q--) {
		int t, i, x;
		cin >> t >> i >> x;
		--i;
		if (t == 1) {
			tree.change(0, a[i], -1);
			a[i] = x;
			tree.change(0, a[i], +1);
		} else {
			tree.change(0, b[i], +1);
			b[i] = x;
			tree.change(0, b[i], -1);
		}
		cout << (tree.p[1] <= 0 ? -1 : tree.find_last() + 1) << '\n';
	}
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll int
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[8200000] = {0},extra[8200000] = {0} ;
const ll M = 1100000;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else if((SGT[id+id]+add+extra[id])>0)return query(id+id,s,mid,add+extra[id]);
	else return {-INF,-INF};
}

ll a[M] = {0},b[M] = {0};

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,1,M,1,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,1,M,1,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,a[ind],-1);
			a[ind] = x;
			upd(1,1,M,1,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,b[ind],1);
			b[ind]=x;
			upd(1,1,M,1,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,1,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz = (sizeof(SGT) + sizeof(extra) + sizeof(a) + sizeof(b) )/(1024*1024);
	// cout << sz << endl;

	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll int
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[8200000] = {0},extra[8200000] = {0} ;
const ll M = 1100000;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else if((SGT[id+id]+add+extra[id])>0)return query(id+id,s,mid,add+extra[id]);
	else return {-INF,-INF};
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[n+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,1,M,1,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,1,M,1,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,a[ind],-1);
			a[ind] = x;
			upd(1,1,M,1,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,b[ind],1);
			b[ind]=x;
			upd(1,1,M,1,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,1,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz = (sizeof(SGT) + sizeof(extra))/(1024*1024);
	// cout << sz << endl;

	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll int
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[8200000] = {0},extra[8200000] = {0} ;
const ll M = 1100000;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else if((SGT[id+id]+add+extra[id])>0)return query(id+id,s,mid,add+extra[id]);
	else return {-INF,-INF};
}

ll a[M] = {0},b[M] = {0};

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,1,M,1,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,1,M,1,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,a[ind],-1);
			a[ind] = x;
			upd(1,1,M,1,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,b[ind],1);
			b[ind]=x;
			upd(1,1,M,1,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,1,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz = (sizeof(SGT) + sizeof(extra) + sizeof(a) + sizeof(b) )/(1024*1024);
	// cout << sz << endl;

	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll int
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[5200000] = {0},extra[5200000] = {0} ;
const ll M = 1100000;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else return query(id+id,s,mid,add+extra[id]);
}

ll query1(ll id,ll s,ll e,ll ind){
	if(s == e){
		return SGT[id];
	}
	else {
		ll mid = (s+e)/2;
		if(ind<=mid)return query1(id+id,s,mid,ind) + extra[id];
		else return query1(id+id+1,mid+1,e,ind) + extra[id];
	}
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[n+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,0,M,0,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,0,M,0,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,a[ind],-1);
			a[ind] = x;
			upd(1,0,M,0,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,b[ind],1);
			b[ind]=x;
			upd(1,0,M,0,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,0,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz= (sizeof(SGT) + sizeof (extra))/(1024*1024);
//
	// cout << sz << endl;
	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll long long
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[4200000],extra[4200000] = {0} ;
const ll M = 1000010;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else return query(id+id,s,mid,add+extra[id]);
}

ll query1(ll id,ll s,ll e,ll ind){
	if(s == e){
		return SGT[id];
	}
	else {
		ll mid = (s+e)/2;
		if(ind<=mid)return query1(id+id,s,mid,ind) + extra[id];
		else return query1(id+id+1,mid+1,e,ind) + extra[id];
	}
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[n+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,0,M,0,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,0,M,0,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,a[ind],-1);
			a[ind] = x;
			upd(1,0,M,0,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,b[ind],1);
			b[ind]=x;
			upd(1,0,M,0,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,0,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz= (sizeof(SGT) + sizeof (extra))/(1024*1024);
//
	// cout << sz << endl;
	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll int
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[4200000],extra[4200000] = {0} ;
const ll M = 1000010;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else return query(id+id,s,mid,add+extra[id]);
}

ll query1(ll id,ll s,ll e,ll ind){
	if(s == e){
		return SGT[id];
	}
	else {
		ll mid = (s+e)/2;
		if(ind<=mid)return query1(id+id,s,mid,ind) + extra[id];
		else return query1(id+id+1,mid+1,e,ind) + extra[id];
	}
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[m+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,0,M,0,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,0,M,0,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,a[ind],-1);
			a[ind] = x;
			upd(1,0,M,0,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,b[ind],1);
			b[ind]=x;
			upd(1,0,M,0,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,0,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz= (sizeof(SGT) + sizeof (extra))/(1024*1024);
//
	// cout << sz << endl;
	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll int
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[5200000] = {0},extra[5200000] = {0} ;
const ll M = 1100000;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else if((SGT[id+id]+add+extra[id])>0)return query(id+id,s,mid,add+extra[id]);
	else return {-INF,-INF};
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[n+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,1,M,1,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,1,M,1,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,a[ind],-1);
			a[ind] = x;
			upd(1,1,M,1,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,b[ind],1);
			b[ind]=x;
			upd(1,1,M,1,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,1,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz= (sizeof(SGT) + sizeof (extra))/(1024*1024);
//
	// cout << sz << endl;
	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll int
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[4200000],extra[4200000] = {0} ;
const ll M = 1100000;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else return query(id+id,s,mid,add+extra[id]);
}

ll query1(ll id,ll s,ll e,ll ind){
	if(s == e){
		return SGT[id];
	}
	else {
		ll mid = (s+e)/2;
		if(ind<=mid)return query1(id+id,s,mid,ind) + extra[id];
		else return query1(id+id+1,mid+1,e,ind) + extra[id];
	}
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[n+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,0,M,0,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,0,M,0,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,a[ind],-1);
			a[ind] = x;
			upd(1,0,M,0,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,b[ind],1);
			b[ind]=x;
			upd(1,0,M,0,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,0,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz= (sizeof(SGT) + sizeof (extra))/(1024*1024);
//
	// cout << sz << endl;
	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll long long
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[4200000],extra[4200000] = {0} ;
const ll M = 1000010;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else return query(id+id,s,mid,add+extra[id]);
}

ll query1(ll id,ll s,ll e,ll ind){
	if(s == e){
		return SGT[id];
	}
	else {
		ll mid = (s+e)/2;
		if(ind<=mid)return query1(id+id,s,mid,ind) + extra[id];
		else return query1(id+id+1,mid+1,e,ind) + extra[id];
	}
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[m+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,0,M,0,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,0,M,0,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,a[ind],-1);
			a[ind] = x;
			upd(1,0,M,0,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,b[ind],1);
			b[ind]=x;
			upd(1,0,M,0,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,0,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz= (sizeof(SGT) + sizeof (extra))/(1024*1024);
//
	// cout << sz << endl;
	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll int
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[5200000] = {0},extra[5200000] = {0} ;
const ll M = 1100000;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else return query(id+id,s,mid,add+extra[id]);
}

ll query1(ll id,ll s,ll e,ll ind){
	if(s == e){
		return SGT[id];
	}
	else {
		ll mid = (s+e)/2;
		if(ind<=mid)return query1(id+id,s,mid,ind) + extra[id];
		else return query1(id+id+1,mid+1,e,ind) + extra[id];
	}
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[n+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,1,M,1,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,1,M,1,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,a[ind],-1);
			a[ind] = x;
			upd(1,1,M,1,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,1,M,1,b[ind],1);
			b[ind]=x;
			upd(1,1,M,1,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,1,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	// size_t sz= (sizeof(SGT) + sizeof (extra))/(1024*1024);
//
	// cout << sz << endl;
	return 0;
}


// Problem : C. Serge and Dining Room
// Contest : Codeforces - Codeforces Round #569 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1179/C
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll long long
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

ll SGT[1200000],extra[1200000] = {0} ;
const ll M = 1000010;

void upd(ll id,ll s,ll e,ll l,ll r,ll val){

	if(s>r || l>e)return;
	if(l<=s && e<=r){
		SGT[id] += val;
		extra[id]+=val;
		return;
	}
	ll mid = (s+e)/2;
	upd(id+id,s,mid,l,r,val);
	upd(id+id+1,mid+1,e,l,r,val);
	SGT[id] = max(SGT[id+id],SGT[id+id+1]) + extra[id];
}

pair<ll,ll>  query(ll id,ll s,ll e,ll add = 0){
	if(s == e)return {s,SGT[id]+add};
	ll mid = (s+e)/2;
	if((SGT[id+id+1]+add + extra[id])>0)return query(id+id+1,mid+1,e,add+extra[id]);
	else return query(id+id,s,mid,add+extra[id]);
}

ll query1(ll id,ll s,ll e,ll ind){
	if(s == e){
		return SGT[id];
	}
	else {
		ll mid = (s+e)/2;
		if(ind<=mid)return query1(id+id,s,mid,ind) + extra[id];
		else return query1(id+id+1,mid+1,e,ind) + extra[id];
	}
}

int main() {
	FAST
	ll n,m;
	cin >> n >> m;
	ll a[n+1] = {0},b[n+1] = {0};
	for(ll i = 1;i<=n;i++){
		cin >> a[i];
		upd(1,0,M,0,a[i],1);
	}
	for(ll i= 1;i<=m;i++){
		cin >> b[i];
		upd(1,0,M,0,b[i],-1);
	}

	ll q;
	cin >> q;
	while(q--){
		ll ty;
		cin >> ty;
		if(ty == 1){
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,a[ind],-1);
			a[ind] = x;
			upd(1,0,M,0,a[ind],1);
		}
		else {
			ll ind,x;
			cin >> ind >> x;
			upd(1,0,M,0,b[ind],1);
			b[ind]=x;
			upd(1,0,M,0,b[ind],-1);
		}
		pair<ll,ll> chk = query(1,0,M);

		if(chk.S<=0){
			cout << -1 << endl;
		}
		else {
			cout << chk.F << endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pb push_back
const int maxi = 3e6+10;
const int sz = 1<<20;
string s;
int n,m;
int a[maxi];
int b[maxi];
vector<int> v[maxi];
long long  tree[maxi];
long long  lazy[maxi];

void update(int node, int tl, int tr, int l, int r, int val)
{
    if (tr<l || tl>r)
    {
        tree[node]+=lazy[node];
        if (tr!=tl)
        {
            lazy[2*node]+=lazy[node];
            lazy[2*node+1]+=lazy[node];
        }
        lazy[node] = 0;
        return;
    }

    if (r>=tr && l<=tl)
    {
        tree[node]+=lazy[node]+val;

        if (tr!=tl)
        {
            lazy[2*node]+=lazy[node]+val;
            lazy[2*node+1]+=lazy[node]+val;
        }
        lazy[node] = 0;

        return;
    }

    lazy[2*node] +=lazy[node];
    lazy[2*node+1] +=lazy[node];
    lazy[node] = 0;

    update(2*node, tl, (tr+tl)/2, l,r, val);
    update(2*node+1, (tr+tl)/2 + 1, tr, l, r, val);

    tree[node] = min(tree[2*node], tree[2*node+1]);
}

int get_min(int node, int tl, int tr, int l, int r, long long val)
{
    if (tr<l || tl>r)
        return 1e9;

    if (r>=tr && l<=tl)
    {
        return tree[node]+val+lazy[node];
    }

    int mi1 = get_min(2*node, tl, (tl+tr)/2, l,r, lazy[node]+val);
    int mi2 = get_min(2*node+1, (tl+tr)/2+1, tr, l,r,lazy[node]+val);

    return min(mi1, mi2);

}

int main()
{
    cin>>n>>m;

    for (int i=1; i<=n; i++)
        scanf("%d",&a[i]);

    for (int i=1; i<=m; i++)
        scanf("%d",&b[i]);

    for (int i=1; i<=n; i++)
        update(1,1,sz,1, a[i], -1);

    for (int i=1; i<=m; i++)
        update(1,1,sz,1, b[i], 1);

    int q;
    cin>>q;

    while(q--)
    {
        int tip,x,y;
        scanf("%d%d%d",&tip,&x,&y);
        if (tip==1)
        {
            update(1,1,sz,1,a[x],1);
            update(1,1,sz,1,y,-1);
            a[x]=y;
        }
        else
        {
            update(1,1,sz,1,b[x],-1);
            update(1,1,sz,1,y,1);
            b[x] = y;
        }

        int l = 0;
        int r = sz+1;

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

        if (l==0)
            printf("-1\n");
        else
            printf("%d\n",l);
    }
    return 0;
}
//laku noc, moja mala barbiko
//dzaba sve, al ja sam na te naviko


#include<bits/stdc++.h>

using namespace std;

#define pb push_back
const int maxi = 2e6+10;
const int sz = 1<<20;
string s;
int n,m;
int a[maxi];
int b[maxi];
vector<int> v[maxi];
long long  tree[maxi];
long long  lazy[maxi];

void update(int node, int tl, int tr, int l , int r, int val)
{
    if (tr<l || tl>r) return;

    if (r>=tr && l<=tl)
    {
        tree[node]+=lazy[node]+val;

        if (tr!=tl)
        {
            lazy[2*node]+=lazy[node]+val;
            lazy[2*node+1]+=lazy[node]+val;
        }
        lazy[node] = 0;

        return;
    }

    lazy[2*node] +=lazy[node];
    lazy[2*node+1] +=lazy[node];
    lazy[node] = 0;

    update(2*node, tl, (tr+tl)/2, l ,r, val);
    update(2*node+1, (tr+tl)/2 + 1, tr, l, r, val);

    tree[node] = min(tree[2*node], tree[2*node+1]);
}

int get_min(int node, int tl, int tr, int l, int r, long long val)
{
    if (tr<l || tl>r) return 1e9;

     if (r>=tr && l<=tl)
    {
         return tree[node]+val+lazy[node];
    }

    int mi1 = get_min(2*node, tl, (tl+tr)/2, l ,r, lazy[node]+val);
    int mi2 = get_min(2*node+1, (tl+tr)/2+1, tr, l ,r,lazy[node]+val);

    return min(mi1, mi2);

}

int main()
{
    cin>>n>>m;

    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);

    for (int i=1;i<=m;i++)
        scanf("%d",&b[i]);

    for (int i=1;i<=n;i++)
        update(1,1,sz,1, a[i], -1);

    for (int i=1;i<=m;i++)
        update(1,1,sz,1, b[i], 1);

    int q;
    cin>>q;

    while(q--)
    {
        int tip,x,y;
        scanf("%d%d%d",&tip,&x,&y);
        if (tip==1)
        {
            update(1,1,sz,1,a[x],1);
            update(1,1,sz,1,y,-1);
            a[x]=y;
        } else
        {
             update(1,1,sz,1,b[x],-1);
             update(1,1,sz,1,y,1);
             b[x] = y;
        }

        int l = 0;
        int r = sz+1;

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

        if (l==0) printf("-1\n"); else
            printf("%d\n",l);
    }
    return 0;
}
//laku noc, moja mala barbiko
//dzaba sve, al ja sam na te naviko


#include<bits/stdc++.h>

using namespace std;

#define pb push_back
const int maxi = 2e6+10;
const int sz = 1<<20;
string s;
int n,m;
int a[maxi];
int b[maxi];
vector<int> v[maxi];
long long  tree[maxi];
long long  lazy[maxi];

void update(int node, int tl, int tr, int l, int r, int val)
{
    if (tr<l || tl>r)
    {
        tree[node]+=lazy[node];
        if (tr!=tl)
        {
            lazy[2*node]+=lazy[node];
            lazy[2*node+1]+=lazy[node];
        }
        lazy[node] = 0;
        return;
    }

    if (r>=tr && l<=tl)
    {
        tree[node]+=lazy[node]+val;

        if (tr!=tl)
        {
            lazy[2*node]+=lazy[node]+val;
            lazy[2*node+1]+=lazy[node]+val;
        }
        lazy[node] = 0;

        return;
    }

    lazy[2*node] +=lazy[node];
    lazy[2*node+1] +=lazy[node];
    lazy[node] = 0;

    update(2*node, tl, (tr+tl)/2, l,r, val);
    update(2*node+1, (tr+tl)/2 + 1, tr, l, r, val);

    tree[node] = min(tree[2*node], tree[2*node+1]);
}

int get_min(int node, int tl, int tr, int l, int r, long long val)
{
    if (tr<l || tl>r)
        return 1e9;

    if (r>=tr && l<=tl)
    {
        return tree[node]+val+lazy[node];
    }

    int mi1 = get_min(2*node, tl, (tl+tr)/2, l,r, lazy[node]+val);
    int mi2 = get_min(2*node+1, (tl+tr)/2+1, tr, l,r,lazy[node]+val);

    return min(mi1, mi2);

}

int main()
{
    cin>>n>>m;

    for (int i=1; i<=n; i++)
        scanf("%d",&a[i]);

    for (int i=1; i<=m; i++)
        scanf("%d",&b[i]);

    for (int i=1; i<=n; i++)
        update(1,1,sz,1, a[i], -1);

    for (int i=1; i<=m; i++)
        update(1,1,sz,1, b[i], 1);

    int q;
    cin>>q;

    while(q--)
    {
        int tip,x,y;
        scanf("%d%d%d",&tip,&x,&y);
        if (tip==1)
        {
            update(1,1,sz,1,a[x],1);
            update(1,1,sz,1,y,-1);
            a[x]=y;
        }
        else
        {
            update(1,1,sz,1,b[x],-1);
            update(1,1,sz,1,y,1);
            b[x] = y;
        }

        int l = 0;
        int r = sz+1;

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

        if (l==0)
            printf("-1\n");
        else
            printf("%d\n",l);
    }
    return 0;
}
//laku noc, moja mala barbiko
//dzaba sve, al ja sam na te naviko


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lll long long

using namespace std;
const lll NR= 3e5 + 10,oo = 2e12 + 10, MOD = 1e9 + 7;
const long double pi = 2*acos(0.0);
vector < int > Tree ( NR << 2 , 0 ) ;
vector < int > Lazy ( NR << 2 , 0 ) ;
struct stud     {
    int type, pos , val ;
};
int type, pos , val , a [NR], b[NR] ;
vector < stud > query;
vector < int > all;

map < int , int > mpp;
int  n , m , q ;

void push ( int nod , int st , int dr , int level ) {
    if ( level == 2 )   return ;
    if ( st == dr ) {
        Tree [ nod ] += Lazy [ nod ] ;
        Lazy [ nod ] = 0 ;
        return ;
    }
    Lazy [ nod << 1 ] += Lazy [ nod ] ;
    Lazy [ nod << 1 | 1 ] += Lazy [ nod ] ;
    Lazy [ nod ] = 0 ;
    int mij = ( st + dr ) >> 1 ;
    push ( nod << 1 , st , mij , level + 1 ) ;
    push ( nod << 1 | 1 , mij + 1 , dr , level + 1 ) ;
}

void range_update ( int nod, int st , int dr , int a, int b , int val ) {
    push ( nod , st , dr , 0 ) ;
    if ( a <= st && dr <= b )   {
        Lazy [ nod ] += val ;
        push ( nod , st , dr , 0 ) ;
        if ( st != dr )
        Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( a <= mij ) range_update( nod << 1 , st , mij , a , b , val ) ;
    if ( mij <  b ) range_update( nod << 1 | 1 , mij + 1 , dr , a , b , val ) ;
    push ( nod , st , dr , 0 ) ;
    Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;
}

int querry ( int nod , int st , int dr )   {
    push( nod , st , dr , 0 ) ;
    if ( st != dr )
    Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;

    if ( Tree [ nod ] <= 0 )    return 0 ;
   if ( st == dr )
       return st ;
   int mij = ( st + dr ) >> 1 ;
   if ( Tree [ nod << 1 | 1 ] > 0 )
       return querry( nod << 1 | 1 , mij + 1 , dr ) ;
    return querry ( nod << 1 , st , mij ) ;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i ;
    stud c ;
    cin >> n >> m ;
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> a [ i ] ;
        all.pb( a [ i ] ) ;
    }
    for ( i = 1 ; i <= m ; ++ i )   {
        cin >> b [ i ] ;
        all.pb( b [ i ] ) ;
    }
    cin >> q ;
    while ( q -- )  {
        cin >> c.type >> c.pos >> c.val ;
        query.pb(c);
        all.pb( c.val ) ;
    }
    all.pb(-1);
    sort ( all.begin(), all.end() ) ;
    all.erase( unique(all.begin(), all.end()) , all.end() );
    auto norm = [&](int x) {
        return lower_bound(all.begin(), all.end(), x) - all.begin();
    };
    for ( i = 0 ; i < all.size() ; ++ i )
        mpp [ all [ i ] ] = norm ( all [ i ] ) ;

    for ( i = 1 ; i <= n ; ++ i )   {
        range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ i ] ] , 1 ) ;
    }
    for ( i = 1 ; i <= m ; ++ i )   {
        range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ i ] ] , -1 ) ;
    }
    for ( i = 0 ; i < query.size() ; ++ i ) {
        c = query[i];

        if ( c.type == 1 )  {
            range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ c.pos ] ] , -1 );
            a [ c.pos ] = c.val ;
            range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ c.pos ] ] , 1 ) ;
        } else  {
            range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ c.pos ] ] , 1 );
            b [ c.pos ] = c.val ;
            range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ c.pos ] ] , -1 ) ;
        }
        cout << all [ querry ( 1 , 1 , 1000000 ) ] << '\n' ;
    }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lll long long

using namespace std;
const lll NR= 6e5 + 10,oo = 2e12 + 10, MOD = 1e9 + 7;
const long double pi = 2*acos(0.0);
vector < int > Tree ( NR << 2 , 0 ) ;
vector < int > Lazy ( NR << 2 , 0 ) ;
struct stud     {
    int type, pos , val ;
};
int type, pos , val , a [NR], b[NR] ;
vector < stud > query;
vector < int > all;

map < int , int > mpp;
int  n , m , q ;

void push ( int nod , int st , int dr , int level ) {
    if ( level == 2 )   return ;
    if ( st == dr ) {
        Tree [ nod ] += Lazy [ nod ] ;
        Lazy [ nod ] = 0 ;
        return ;
    }
    Lazy [ nod << 1 ] += Lazy [ nod ] ;
    Lazy [ nod << 1 | 1 ] += Lazy [ nod ] ;
    Tree [ nod ] += Lazy [ nod ] ;
    Lazy [ nod ] = 0 ;
    int mij = ( st + dr ) >> 1 ;
    push ( nod << 1 , st , mij , level + 1 ) ;
    push ( nod << 1 | 1 , mij + 1 , dr , level + 1 ) ;
}

void range_update ( int nod, int st , int dr , int a, int b , int val ) {
    push ( nod , st , dr , 0 ) ;

    if ( a <= st && dr <= b )   {
        Lazy [ nod ] += val ;
        push ( nod , st , dr , 0 ) ;
        if ( st != dr )
        Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( a <= mij ) range_update( nod << 1 , st , mij , a , b , val ) ;
    if ( mij <  b ) range_update( nod << 1 | 1 , mij + 1 , dr , a , b , val ) ;
    push ( nod , st , dr , 0 ) ;
    Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;
}

int element_query ( int nod, int st , int dr , int pos )   {
    push ( nod , st , dr , 0 ) ;

    if ( st == dr )
        return Tree [ nod ] ;
    Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )
        return element_query( nod << 1 , st , mij , pos ) ;
    else
        return element_query( nod << 1 | 1 , mij + 1 , dr , pos ) ;
}

int querry ( int nod , int st , int dr )   {
    push( nod , st , dr , 0 ) ;
    if ( st != dr )
    Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;

    if ( Tree [ nod ] <= 0 )    return 0 ;
   if ( st == dr )
       return st ;
   int mij = ( st + dr ) >> 1 ;
   if ( Tree [ nod << 1 | 1 ] > 0 )
       return querry( nod << 1 | 1 , mij + 1 , dr ) ;
    return querry ( nod << 1 , st , mij ) ;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i , j ;
    stud c ;
    cin >> n >> m ;
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> a [ i ] ;
        all.pb( a [ i ] ) ;
    }
    for ( i = 1 ; i <= m ; ++ i )   {
        cin >> b [ i ] ;
        all.pb( b [ i ] ) ;
    }
    cin >> q ;
    while ( q -- )  {
        cin >> c.type >> c.pos >> c.val ;
        query.pb(c);
        all.pb( c.val ) ;
    }
    all.pb(-1);
    sort ( all.begin(), all.end() ) ;
    all.erase( unique(all.begin(), all.end()) , all.end() );
    auto norm = [&](int x) {
        return lower_bound(all.begin(), all.end(), x) - all.begin();
    };
    for ( i = 0 ; i < all.size() ; ++ i )
        mpp [ all [ i ] ] = norm ( all [ i ] ) ;

    for ( i = 1 ; i <= n ; ++ i )   {
        range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ i ] ] , 1 ) ;
    }
    for ( i = 1 ; i <= m ; ++ i )   {
        range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ i ] ] , -1 ) ;
    }

    for ( i = 0 ; i < query.size() ; ++ i ) {
        c = query[i];

        if ( c.type == 1 )  {
            range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ c.pos ] ] , -1 );
            a [ c.pos ] = c.val ;
            range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ c.pos ] ] , 1 ) ;
        } else  {
            range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ c.pos ] ] , 1 );
            b [ c.pos ] = c.val ;
            range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ c.pos ] ] , -1 ) ;
        }
        cout << all [ querry ( 1 , 1 , 1000000 ) ] << '\n' ;

    }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lll long long

using namespace std;
const lll NR= 3e5 + 10,oo = 2e12 + 10, MOD = 1e9 + 7;
const long double pi = 2*acos(0.0);
vector < int > Tree ( NR << 2 , 0 ) ;
vector < int > Lazy ( NR << 2 , 0 ) ;
struct stud     {
    int type, pos , val ;
};
int type, pos , val , a [NR], b[NR] ;
vector < stud > query;
vector < int > all;

map < int , int > mpp;
int  n , m , q ;

void push ( int nod , int st , int dr , int level ) {
    if ( level == 2 )   return ;
    if ( st == dr ) {
        Tree [ nod ] += Lazy [ nod ] ;
        Lazy [ nod ] = 0 ;
        return ;
    }
    Lazy [ nod << 1 ] += Lazy [ nod ] ;
    Lazy [ nod << 1 | 1 ] += Lazy [ nod ] ;
    Tree [ nod ] += Lazy [ nod ] ;
    Lazy [ nod ] = 0 ;
    int mij = ( st + dr ) >> 1 ;
    push ( nod << 1 , st , mij , level + 1 ) ;
    push ( nod << 1 | 1 , mij + 1 , dr , level + 1 ) ;
}

void range_update ( int nod, int st , int dr , int a, int b , int val ) {
    push ( nod , st , dr , 0 ) ;

    if ( a <= st && dr <= b )   {
        Lazy [ nod ] += val ;
        push ( nod , st , dr , 0 ) ;
        if ( st != dr )
        Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( a <= mij ) range_update( nod << 1 , st , mij , a , b , val ) ;
    if ( mij <  b ) range_update( nod << 1 | 1 , mij + 1 , dr , a , b , val ) ;
    push ( nod , st , dr , 0 ) ;
    Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;
}

int element_query ( int nod, int st , int dr , int pos )   {
    push ( nod , st , dr , 0 ) ;

    if ( st == dr )
        return Tree [ nod ] ;
    Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )
        return element_query( nod << 1 , st , mij , pos ) ;
    else
        return element_query( nod << 1 | 1 , mij + 1 , dr , pos ) ;
}

int querry ( int nod , int st , int dr )   {
    push( nod , st , dr , 0 ) ;
    if ( st != dr )
    Tree [ nod ] = max ( Tree [ nod << 1 ] , Tree [ nod << 1 | 1 ] ) ;

    if ( Tree [ nod ] <= 0 )    return 0 ;
   if ( st == dr )
       return st ;
   int mij = ( st + dr ) >> 1 ;
   if ( Tree [ nod << 1 | 1 ] > 0 )
       return querry( nod << 1 | 1 , mij + 1 , dr ) ;
    return querry ( nod << 1 , st , mij ) ;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i , j ;
    stud c ;
    cin >> n >> m ;
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> a [ i ] ;
        all.pb( a [ i ] ) ;
    }
    for ( i = 1 ; i <= m ; ++ i )   {
        cin >> b [ i ] ;
        all.pb( b [ i ] ) ;
    }
    cin >> q ;
    while ( q -- )  {
        cin >> c.type >> c.pos >> c.val ;
        query.pb(c);
        all.pb( c.val ) ;
    }
    all.pb(-1);
    sort ( all.begin(), all.end() ) ;
    all.erase( unique(all.begin(), all.end()) , all.end() );
    auto norm = [&](int x) {
        return lower_bound(all.begin(), all.end(), x) - all.begin();
    };
    for ( i = 0 ; i < all.size() ; ++ i )
        mpp [ all [ i ] ] = norm ( all [ i ] ) ;

    for ( i = 1 ; i <= n ; ++ i )   {
        range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ i ] ] , 1 ) ;
    }
    for ( i = 1 ; i <= m ; ++ i )   {
        range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ i ] ] , -1 ) ;
    }

    for ( i = 0 ; i < query.size() ; ++ i ) {
        c = query[i];

        if ( c.type == 1 )  {
            range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ c.pos ] ] , -1 );
            a [ c.pos ] = c.val ;
            range_update( 1 , 1 , 1000000 , 1 , mpp [ a [ c.pos ] ] , 1 ) ;
        } else  {
            range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ c.pos ] ] , 1 );
            b [ c.pos ] = c.val ;
            range_update( 1 , 1 , 1000000 , 1 , mpp [ b [ c.pos ] ] , -1 ) ;
        }
        cout << all [ querry ( 1 , 1 , 1000000 ) ] << '\n' ;

    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 3e5 + 1;
const int M = 1e6 + 1;
int n, m, q;

int a[N];
int b[N];
int suf[M];

struct Node {
    int l, r;
    int mxm;
    int lzy;
} node[M << 2];

void lazy(int id) {
    int lzy = node[id].lzy;
    if(!lzy) {
        return;
    }
    if(node[id].l != node[id].r) {
        node[l(id)].lzy += lzy;
        node[r(id)].lzy += lzy;
    }
    node[id].mxm += lzy;
    node[id].lzy = 0;
}

void merge(int id, int l, int r) {
    lazy(l), lazy(r);
    node[id].mxm = max(node[l].mxm, node[r].mxm);
}

void build(int id, int l, int r) {
    node[id].l = l;
    node[id].r = r;
    if(l == r) {
        node[id].mxm = suf[l];
        return;
    }
    int q = l + r >> 1;
    build(l(id), l, q);
    build(r(id), q + 1, r);
    merge(id, l(id), r(id));
}

void update(int id, int l, int r, int x) {
    if(node[id].l == l && node[id].r == r) {
        node[id].lzy += x;
        return;
    }
    lazy(id);
    int q = node[id].l + node[id].r >> 1;
    if(l <= q) {
        update(l(id), l, min(q, r), x);
    }
    if(r > q) {
        update(r(id), max(q + 1, l), r, x);
    }
    merge(id, l(id), r(id));
}

int query(int id) {
    lazy(id);
    if(node[id].l == node[id].r) {
        return node[id].l;
    }
    lazy(r(id));
    if(node[r(id)].mxm >= 1) {
        return query(r(id));
    } else {
        return query(l(id));
    }
}

void input() {
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        suf[a[i]]++;
    }
    for(int i = 1; i <= m; ++i) {
        cin >> b[i];
        suf[b[i]]--;
    }
    for(int i = M - 2; i >= 0; --i) {
        suf[i] += suf[i + 1];
    }
}

void solve() {
    cin >> q;
    build(0, 0, M - 1);
    for(int i = 0; i < q; ++i) {
        int t; cin >> t;
        int k; cin >> k;
        int x; cin >> x;
        if(t == 1) {
            if(x > a[k]) {
                update(0, a[k] + 1, x, 1);
            } else if(x < a[k]) {
                update(0, x + 1, a[k], -1);
            }
            a[k] = x;
        } else {
            if(x > b[k]) {
                update(0, b[k] + 1, x, -1);
            } else if(x < b[k]) {
                update(0, x + 1, b[k], 1);
            }
            b[k] = x;
        }
        int res = query(0);
        if(res) {
            cout << res << "\n";
        } else {
            cout << "-1\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}