//vanitas vanitatum et omnia vanitas
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
const int N=3e5+5,mod=1e9+7;
int n,s[N],lst[N],m,cur,mul,add,pd,p[N],a[N],tk[N],tq;
int ksm(int x,int y,int r=1) {
for(;y;y>>=1,x=x*x%mod) if(y&1) r=r*x%mod;
return r;
}
signed main() {
n=read(); mul=1;
rep(i,1,n) {
int opt=read();
if(opt==1) {
m++; lst[m]=cur; int k=read(); s[m]=s[m-1]+(tk[m]=k);
if(!k) {
++pd, cur=m, mul=mul*2%mod, add=add*2%mod;
a[m]=(mod+1-add)*ksm(mul,mod-2)%mod;
p[m]=1-pd;
} else {
add+=k;
a[m]=(mod-add)*ksm(mul,mod-2)%mod;
p[m]=-pd;
}
} else if(opt==2) {
int g=read(), x=read();
int sa=(a[g]*mul+add)%mod, sp=p[g]+pd;
printf("%lld\n",(sa+(x-1)*ksm(2,sp))%mod);
} else {
int ans=0, k=read(), ++tq;
for(int x=m;x;) {
if(!tk[x]) {
if(k&1) {ans=x; if(tq==87) puts("T2"); break;}
else k/=2;
x--;
} else {
int ss=s[x]-s[lst[x]];
if(k>ss) k-=ss;
else {
int l=lst[x]+1, r=x;
while(l<=r) {
int mid=l+r>>1;
if(s[x]-s[mid-1]>=k) ans=mid, l=mid+1;
else r=mid-1;
}
break;
if(tq==87) puts("T3");
}
x=lst[x];
}
}
printf("%lld\n",ans);
}
}
return 0;
}