#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define eps 0.00000001
#define ll long long
#define orz puts("-1")
#define pf(x) printf("%s",x);
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define newline puts("")
#define newspace putchar(' ')
#define lowbit(x) (x&(-x))
#define md(l,r) ((l+r)>>1)
#define lson(p) (p<<1)
#define rson(p) ((p<<1)|1)
#define fi first
#define se second
#define inf 2147483647
#define mod
#define N 200010
namespace fastIO{
template<typename T> void read(T &x){
x=0;
char ch=getchar();T fl=1;
while(ch<'0'||ch>'9'){if(ch=='-')fl=-1;ch=getchar();};
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();};
x=x*fl;
}
template<typename T, typename ...T1> void read(T &x, T1 &...x1){
read(x);
read(x1...);
}
template<typename T> void write(T x){
if(x<0){
x=-x;putchar('-');
}
if(x/10)write(x/10);
putchar(x%10+'0');
}
template<typename T> void writer(T x){
write(x);
putchar(' ');
}
template<typename T> void writen(T x){
write(x);
putchar('\n');
}
}
using namespace fastIO;
struct tree {
int ls, rs;
int key;
ll val;
int siz;
ll sum;
int tag;
} t[N << 7];
int root[N], cnt;
int addnew(int x) {
t[++cnt].key = x;
t[cnt].ls = t[cnt].rs = t[cnt].tag = 0;
t[cnt].siz = 1;
t[cnt].sum = x;
t[cnt].val = rand();
return cnt;
}
int getcpy(int x) {
int rt = addnew(0);
t[rt] = t[x];
return rt;
}
void pushup(int u) {
t[u].siz = t[t[u].ls].siz + t[t[u].rs].siz + 1;
t[u].sum = t[t[u].ls].sum + t[t[u].rs].sum + t[u].key;
}
void pushdown(int u) {
if (t[u].tag) {
if (t[u].ls != 0) t[u].ls = getcpy(t[u].ls);
if (t[u].rs != 0) t[u].rs = getcpy(t[u].rs);
swap(t[u].ls, t[u].rs);
t[t[u].ls].tag ^= 1, t[t[u].rs].tag ^= 1;
t[u].tag = 0;
}
}
pii split(int u, int k) {
if (u == 0) return {0, 0};
pushdown(u);
if (t[t[u].ls].siz + 1 <= k) {
pii tp = split(t[u].rs, k - (t[t[u].ls].siz + 1));
if (tp.fi != 0) t[u].rs = getcpy(tp.fi), pushup(t[u].rs);
else t[u].rs = 0;
pushup(u);
return {u, tp.se};
} else {
pii tp = split(t[u].ls, k);
if (tp.se != 0) t[u].ls = getcpy(tp.se), pushup(t[u].ls);
else t[u].ls = 0;
pushup(u);
return {tp.fi, u};
}
}
int merge(int u, int v) {
if (!u || !v) return u + v;
pushdown(u);pushdown(v);
if (t[u].val > t[v].val) {
t[u].rs = merge(t[u].rs, v);
pushup(u);
return u;
} else {
t[v].ls = merge(u, t[v].ls);
pushup(v);
return v;
}
}
void inorder(int u) {
if (u == 0) return ;
inorder(t[u].ls);
if (t[u].key == 0) writen(u);
writer(t[u].key);
inorder(t[u].rs);
}
int tot, n;
signed main() {
srand(time(0));
read(n);
ll lst = 0;
while (n--) {
int v, op;
read(v, op);
if (op == 1) {
ll x, y;
read(x, y);
x ^= lst, y ^= lst;
pii tp = split(root[v], x);
root[++tot] = merge(merge(tp.fi, addnew(y)), tp.se);
} else if (op == 2) {
ll x;
read(x);
x ^= lst;
pii tp = split(root[v], x);
pii opt = split(tp.fi, x - 1);
root[++tot] = merge(opt.fi, tp.se);
} else if (op == 3) {
ll l, r;
read(l, r);
l ^= lst, r ^= lst;
pii tp = split(root[v], r);
pii opt = split(tp.fi, l - 1);
t[opt.se].tag ^= 1;
root[++tot] = merge(merge(opt.fi, opt.se), tp.se);
} else {
ll l, r;
read(l, r);
l ^= lst, r ^= lst;
pii tp = split(root[v], r);
pii opt = split(tp.fi, l - 1);
lst = t[opt.se].sum;
writen(lst);
root[++tot] = merge(merge(opt.fi, opt.se), tp.se);
}
}
return 0;
}