#ifndef NOSTDCPP
#include <bits/stdc++.h>
#else
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <complex>
#include <cstring>
#include <cstdio>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#endif
# ifdef Linux_System
# define getchar getchar_unlocked
# define putchar putchar_unlocked
# endif
# define RESET(_) memset(_, 0, sizeof(_))
# define RESET_(_, val) memset(_, val, sizeof(_))
# define fi first
# define se second
# define pb push_back
# define midf(x, y) ((x + y) >> 1)
# define DXA(_) (((_) << 1))
# define DXB(_) (((_) << 1) | 1)
# define next __Chtholly__
# define x1 __Mercury__
# define y1 __bbtl04__
# define index __ikooo__
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef set <int> si;
typedef pair <int, int> pii;
typedef long double ld;
const int MOD = 1e9 + 7;
const int maxn = 400009;
const int maxm = 300009;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;
ll myrand(ll mod){return ((ll)rand() << 32 ^ (ll)rand() << 16 ^ rand()) % mod;}
template <class T>
inline bool scan_d(T & ret)
{
char c;
int sgn;
if(c = getchar(), c == EOF)return false;
while(c != '-' && (c < '0' || c > '9'))c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while(c = getchar(), c >= '0' && c <= '9')
ret = ret * 10 + (c - '0');
ret *= sgn;
return true;
}
#ifdef Cpp11
template <class T, class ... Args>
inline bool scan_d(T & ret, Args & ... args)
{
scan_d(ret);
scan_d(args...);
}
#define cin.tie(0); cin.tie(nullptr);
#define cout.tie(0); cout.tie(nullptr);
#endif
inline bool scan_ch(char &ch)
{
if(ch = getchar(), ch == EOF)return false;
while(ch == ' ' || ch == '\n')ch = getchar();
return true;
}
template <class T>
inline void out_number(T x)
{
if(x < 0)
{
putchar('-');
out_number(- x);
return ;
}
if(x > 9)out_number(x / 10);
putchar(x % 10 + '0');
}
int n, m, Min[maxn << 2], key[maxn], pro[maxn], siz;
struct pile
{
int val, pro;
pile(int val = 0, int pro = 0) : val(val), pro(pro) {}
bool operator < (const pile &b) const
{
return (val < b.val) | (val == b.val && pro < b.pro);
}
};
vector <pile> v;
map <int, int> key_to_query, priority_to_query;
inline void pushup(int p){Min[p] = min(Min[DXA(p)], Min[DXB(p)]);}
void pre(int l, int r, int p)
{
if(l == r) {Min[p] = inf; return;}
int mid = midf(l, r);
pre(l, mid, DXA(p));
pre(mid + 1, r, DXB(p));
pushup(p);
}
int val, priority, l, r;
void update(int nl, int nr, int p)
{
if(nl == nr) {Min[p] = val; return ;}
int mid = midf(nl, nr);
if(priority <= mid) update(nl, mid, DXA(p));
else update(mid + 1, nr, DXB(p));
pushup(p);
}
int query(int nl, int nr, int p)
{
if(l <= nl && nr <= r) return Min[p];
int mid = midf(nl, nr), ans = inf;
if(l <= mid) ans = min(ans, query(nl, mid, DXA(p)));
if(mid < r) ans = min(ans, query(mid + 1, nr, DXB(p)));
return ans;
}
char op[maxm];
int A[maxm], B[maxm];
int main()
{
ios :: sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
scanf("%d %d", &n, &m);
siz = n;
for(register int i = 1; i <= n; ++ i) scanf("%d", key + i);
for(register int i = 1; i <= n; ++ i) scanf("%d", pro + i);
for(register int i = 1; i <= n; ++ i) v.pb(pile(key[i], pro[i]));
for(register int i = 1; i <= m; ++ i)
{
scanf("\n%c", &op[i]);
switch(op[i])
{
case 'I':
scanf("%d %d", A + i, B + i);
key[++ siz] = A[i];
pro[siz] = B[i];
v.pb(pile(A[i], B[i]));
break;
case 'D':
scanf("%d", A + i);
break;
case 'Q':
scanf("%d %d", A + i, B + i);
break;
}
}
sort(v.begin(), v.end());
pre(1, siz, 1);
for(register int i = 1; i <= n; ++ i)
{
priority = key_to_query[key[i]] = priority_to_query[pro[i]] = lower_bound(v.begin(), v.end(), pile(key[i], pro[i])) - v.begin() + 1;
val = pro[i];
update(1, siz, 1);
}
for(register int i = 1, p; i <= m; ++ i)
{
if(op[i] == 'I')
{
priority = key_to_query[A[i]] = priority_to_query[B[i]] = lower_bound(v.begin(), v.end(), pile(A[i], B[i])) - v.begin() + 1;
val = B[i];
update(1, siz, 1);
}
else if(op[i] == 'D')
{
val = inf;
priority = key_to_query[A[i]];
update(1, siz, 1);
}
else
{
l = key_to_query[A[i]], r = key_to_query[B[i]];
if(l > r) swap(l, r);
p = query(1, siz, 1);
printf("%d\n", v[priority_to_query[p] - 1].val);
}
}
return 0;
}