#include<bits/stdc++.h>usingnamespacestd;intmx=4*(int)1e6+4;voidsolve(){// dp[v] is the longest missing streak starting at value v.
vector<int>dp(mx,mx);intn;cin>>n;for(inti=0;i<n;i++){intx;cin>>x;dp[x]=0;}// Reconstruct the entire DP table.
for(inti=mx-2;i>=0;i--){if(dp[i]!=0){dp[i]=1+dp[i+1];}}intm;cin>>m;while(m--){chartype;cin>>type;if(type=='+'){intx;cin>>x;// Reconstruct the DP array to the left.
for(inti=0;i<x;i++){intdist=x-i;if(dp[i]>dist){dp[i]-=dp[x];}}dp[x]=0;}if(type=='-'){intx;cin>>x;dp[x]=1+dp[x+1];// Reconstruct the DP array to the left.
for(inti=0;i<x;i++){intdist=x-i;if(dp[i]==dist){dp[i]+=dp[x];}}}if(type=='?'){intk;cin>>k;for(inti=1;i<mx;i++){if(dp[i]>=k){cout<<i<<" ";break;}}}}cout<<endl;}intmain(){ios_base::sync_with_stdio(false);cin.tie(NULL);intt;cin>>t;for(inti=0;i<t;i++){solve();}return0;}