#include <bits/stdc++.h>
namespace IO{
#define LL long long
inline LL read(){
LL x=0,f=1;char c=getchar();
for (;!isdigit(c);c=getchar())if (c=='-')f=-1;
for (;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
return x*f;
}
inline void write(LL x,char c='\n'){
if (x){
if (x<0)x=-x,putchar('-');
char a[30];short l;
for (l=0;x;x/=10)a[l++]=x%10^48;
for (l--;l>=0;l--)putchar(a[l]);
}else putchar('0');putchar(c);
}
}using namespace IO;
using namespace std;
#define int long long
const int N = 2e5+10;
struct Treap{int l,r,val,key,siz,tag,sum;}tree[N<<7];
int cnt,root[N];
int newnode(int x){
tree[++cnt].siz=1;
tree[cnt].l=tree[cnt].r=0;
tree[cnt].val=x;
tree[cnt].sum=x;
tree[cnt].key=rand();
tree[cnt].tag=0;
return cnt;
}
int Copy(int x){
int ret=newnode(0);
tree[ret]=tree[x];
return ret;
}
void pushup(int x){
tree[x].siz=tree[tree[x].l].siz+tree[tree[x].r].siz+1;
tree[x].sum=tree[tree[x].r].sum+tree[tree[x].r].sum+tree[x].val;
}
void pushdown(int x){
if (!tree[x].tag)return ;
if (tree[x].l)tree[x].l=Copy(tree[x].l);
if (tree[x].r)tree[x].r=Copy(tree[x].r);
swap(tree[x].l,tree[x].r);
tree[tree[x].l].tag^=1;
tree[tree[x].r].tag^=1;
tree[x].tag=0;
}
void split(int now,int val,int &x,int &y){
if (!now)return x=y=0,void();
pushdown(now);
if (tree[tree[now].l].siz+1<=val)
x=Copy(now),
split(tree[x].r,val-tree[tree[x].l].siz-1,tree[x].r,y),
pushup(x);
else
y=Copy(now);
split(tree[y].l,val,x,tree[y].l),
pushup(y);
}
int merge(int x,int y){
if (!x||!y)return x+y;
pushdown(x);
pushdown(y);
if (tree[x].key>tree[y].key){
tree[x].r=merge(tree[x].r,y);
pushup(x);
return x;
}
else{
tree[y].l=merge(x,tree[y].l);
pushup(y);
return y;
}
}
signed main(){
srand(time(0));
int n=read(),lastans=0,x,y,l,r,tmp,c=0;
for (int i=1;i<=n;i++){
int v=read(),opt=read();
if (opt==1)
x=read()^lastans,y=read()^lastans,
split(root[v],x,l,tmp),
root[++c]=merge(merge(l,newnode(y)),tmp);
if (opt==2)
x=read()^lastans,
split(root[v],x,l,r),
split(l,x-1,l,tmp),
root[++c]=merge(l,r);
if (opt==3)
x=read()^lastans,y=read()^lastans,
split(root[v],y,l,r),
split(l,x-1,l,tmp),
tree[tmp].tag^=1,
root[++c]=merge(merge(l,tmp),r);
if (opt==4)
x=read()^lastans,y=read()^lastans,
split(root[v],y,l,r),
split(l,x-1,l,tmp),
lastans=tree[tmp].sum,
write(lastans),
root[++c]=merge(merge(l,tmp),r);
}
return 0;
}