#include <bits/stdc++.h>
#define booost ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fi first
#define se second
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;


struct SegmentTree /// (+, sum)
{
    const static int MAX = 1 << 20;
    LL INF = LL(1e18) + 7;
    vector < LL > tree;
    SegmentTree()
    {
        tree.resize(2 * MAX, 0);
    }
    void update(int a, LL val)
    {
        a += MAX;
        tree[a]+=val;
        a/=2;
        while(a) tree[a] = tree[2*a]+tree[2*a+1], a /= 2;
    }
    LL query(int a, int b)
    {
        a += MAX, b += MAX;
        if(a==b) return tree[a];
        LL res = tree[a]+ tree[b];
        while(a / 2 != b / 2)
        {
            if(a % 2 == 0) res += tree[a + 1];
            if(b % 2 == 1) res +=  tree[b - 1];
            a /= 2, b /= 2;
        }
        return res;
    }
};


const LL MOD=1e9+7;
const LL LLINF=1e18+7;

SegmentTree tree,treecheck;

vector<LL> rybki;
map<LL,int> mpszpr;///tu gdzie wleci następna --- -1, aby znać ostatnią która jest
vector<pair<int,PLL>> queries;
deque<PII> segments;

multiset<LL> szprotki;

int binsearch(PII interval, LL goal)/// left idx
{
    //cout<<"bsearch : "<<interval.fi<<" "<<interval.second<<" "<<goal<<'\n';
    int l=interval.fi, r=interval.se;
    int ans=l;
    while(l<=r)
    {
        int mid=(l+r)/2;
        LL val=tree.query(mid,interval.se);
        //cout<<val<<'\n';
        if(val>=goal)
        {
            ans=mid;
            l=mid+1;
        }
        else
        {
            r=mid-1;
        }
    }
    //cout<<"ans: "<<ans<<'\n';
    return ans;
}

int solve(LL s,LL goal)
{
    if(s>=goal) return 0;
    if( szprotki.empty()) return -1;
    segments.clear();

    auto it=szprotki.lower_bound(s);
    if( it==szprotki.begin()) return -1;
    LL greatest=*(--it);
    LL prev=0;
    segments.push_back({0,mpszpr[greatest]-1});

    int res=0;
    LL curval=s;
    while(curval<goal)
    {
        if(segments.empty()) return -1;
        auto itt=szprotki.upper_bound(greatest);
        LL mingoal=itt==szprotki.end()?goal-1:*itt;
        int left=binsearch(segments.back(),min(mingoal-curval+1,goal-curval));

        //cout<<"res,curval,goal: "<<res<<" "<<curval<<" "<<goal<<'\n';

        res+=treecheck.query(left,segments.back().se);
        curval+=tree.query(left,segments.back().se);

        prev=greatest;
        greatest=*(--szprotki.lower_bound(curval));

        if(curval>=goal)    return res;

        if(left==segments.back().fi)///nastepny
        {
            segments.pop_back();
            if(greatest==prev)  continue;
        }
        else
        {
            int lleft=segments.back().fi;
            segments.pop_back();
            segments.push_back({lleft,left-1});
        }

        if(greatest==prev)
        {
            //cout<<"lel\n";
            return -1;
        }
        else
        {
            segments.push_back({mpszpr[prev],mpszpr[greatest]-1});
        }
    }

    return res;
}
int main()
{
    //booost;
    //freopen("C:/Users/kucha/Documents/ISIM 5. semestr/PA/tests/MS5.in","r",stdin);
    int n,q;
    LL w;
    //cin>>n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        //cin>>w;
        scanf("%lld",&w);
        rybki.push_back(w);
        queries.push_back({2,{w,w}});
    }
    //cin>>q;
    scanf("%d",&q);
    int id;
    LL f,s;
    for(int i=0;i<q;i++)
    {
        //cin>>id;
        scanf("%d",&id);
        if(id==1)
        {
            //cin>>f>>s;
            scanf("%lld %lld",&f,&s);
            queries.push_back({id,{f,s}});
        }
        else
        {
            //cin>>f;
            scanf("%lld",&f);
            queries.push_back({id,{f,f}});
            if(id==2)
            {
                rybki.push_back(f);
            }
        }
    }
    sort(rybki.begin(),rybki.end());
    for(int i=0;i<rybki.size();i++)
    {
        if(mpszpr[rybki[i]]==0)
        {
            mpszpr[rybki[i]]=i;
        }
    }
    mpszpr[rybki[0]]=0;

    for(auto query:queries)
    {
        if(query.fi==1)
        {
            int ans=solve(query.se.fi,query.se.se);
            printf("%d\n",ans);
        }
        else if(query.fi==2)
        {
            tree.update(mpszpr[query.se.fi],query.se.fi);
            treecheck.update(mpszpr[query.se.fi],1);
            mpszpr[query.se.fi]++;
            szprotki.insert(query.se.fi);
        }
        else
        {
            mpszpr[query.se.fi]--;
            tree.update(mpszpr[query.se.fi],-query.se.fi);
            treecheck.update(mpszpr[query.se.fi],-1);
            szprotki.erase(szprotki.find(query.se.fi));
        }
    }

}

