#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define rep for(int i=0;i<=1;i++)
using namespace std;
struct kd
{
int sm[2],sn[2],v[2],sum,s,ls,rs;
kd (int a,int b,int c) {ls=rs=0,sm[0]=sn[0]=v[0]=a,sm[1]=sn[1]=v[1]=b,s=sum=c;}
kd (){}
};
kd t[200010],p[200010];
int n,m,A,B,C,D,root,ans;
bool cmp(kd a,kd b)
{
return (a.v[D]==b.v[D])?(a.v[D^1]<b.v[D^1]):(a.v[D]<b.v[D]);
}
void pushup(int x,int y)
{
rep t[x].sm[i]=max(t[x].sm[i],t[y].sm[i]),t[x].sn[i]=min(t[x].sn[i],t[y].sn[i]);
t[x].sum+=t[y].sum;
}
int build(int l,int r,int d)
{
if(l>r) return 0;
int mid=l+r>>1;
D=d;
nth_element(p+l,p+mid,p+r+1,cmp);
t[mid]=p[mid];
t[mid].ls=build(l,mid-1,d^1),t[mid].rs=build(mid+1,r,d^1);
if(t[mid].ls) pushup(mid,t[mid].ls);
if(t[mid].rs) pushup(mid,t[mid].rs);
return mid;
}
void ins(int y)
{
int x=root,d=0;
while(x!=y)
{
pushup(x,y);
if(t[y].v[0]==t[x].v[0]&&t[y].v[1]==t[x].v[1])
{
t[x].s+=t[y].s,n--;
return ;
}
if(t[y].v[d]<t[x].v[d]) t[x].ls=(!t[x].ls)?y:t[x].ls,x=t[x].ls;
else t[x].rs=(!t[x].rs)?y:t[x].rs,x=t[x].rs;
d^=1;
}
}
int query(int x)
{
if(!x||t[x].sm[0]<A||t[x].sn[0]>C||t[x].sm[1]<B||t[x].sn[1]>D) return 0;
if(t[x].sm[0]<=C&&t[x].sn[0]>=A&&t[x].sm[1]<=D&&t[x].sn[1]>=B) return t[x].sum;
int ret=0;
if(t[x].v[0]>=A&&t[x].v[0]<=C&&t[x].v[1]>=B&&t[x].v[1]<=D) ret+=t[x].s;
ret+=query(t[x].ls)+query(t[x].rs);
return ret;
}
int rd()
{
int ret=0; char gc=getchar();
while(gc<‘0‘||gc>‘9‘) gc=getchar();
while(gc>=‘0‘&&gc<=‘9‘) ret=ret*10+gc-‘0‘,gc=getchar();
return ret;
}
int main()
{
rd();
int i,j,e;
root=1,m=10000;
while(1)
{
e=rd();
if(e==3) break;
if(e==1)
{
A=rd()^ans,B=rd()^ans,C=rd()^ans;
t[++n]=kd(A,B,C),ins(n);
if(n==m)
{
for(i=1;i<=n;i++) p[i]=kd(t[i].v[0],t[i].v[1],t[i].s);
root=build(1,n,0),m+=10000;
}
}
else
{
A=rd()^ans,B=rd()^ans,C=rd()^ans,D=rd()^ans;
ans=query(root);
printf("%d\n",ans);
}
}
return 0;
}