#include<stdio.h>
int main()
{
long long int nq,x,y,px,py,q,t,i,xindex,yindex,pindex,el[31],ans,ter,len; char a,s[6]; int lc=1;
el[0]=0; el[1]=1;el[2]=3;el[3]=7;el[4]=15;el[5]=31;el[6]=63;el[7]=127;el[8]=255;el[9]=511;el[10]=1023;el[11]=2047;el[12]=4095;el[13]=8191;el[14]=16383;el[15]=32767;el[16]=65535;el[17]=131071;el[18]=262143;el[19]=524287;el[20]=1048575;el[21]=2097151;el[22]=4194303;el[23]=8388607;el[24]=16777215;el[25]=33554431;el[26]=67108863;el[27]=134217727;el[28]=268435455;el[29]=536870911;el[30]=1073741823;
scanf("%lld",&nq);
while((a = getchar()) != '\n' && a != EOF);
while(nq>0)
{
scanf("%s",&s);
if(!(s[1]-'i')){ lc=!lc;}
else
{ scanf("%lld %lld",&x,&y);
// printf("%lld %lld",x,y);
px=x;py=y;
while(px!=py) { if(px>py){px/=2;} else py/=2; }
for(i=0;i<31;i++)
{
if((el[i]<x)&&(el[i+1]>=x))
{ xindex=i+1;}
if((el[i]<y)&&(el[i+1]>=y))
{ yindex=i+1;}
if((el[i]<py)&&(el[i+1]>=py))
{ pindex=i+1;}
}
//printf("%lld",nq);
ans=0;
len=xindex+yindex-2*pindex+1;
if(xindex%2==lc) ans=1;
ans+=(len)/2;
if(s[1]-'b'){ans=len-ans;}
printf("%lld\n",ans);
}
nq--;
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KaW50IG1haW4oKQp7CiAgbG9uZyBsb25nIGludCBucSx4LHkscHgscHkscSx0LGkseGluZGV4LHlpbmRleCxwaW5kZXgsZWxbMzFdLGFucyx0ZXIsbGVuOyBjaGFyIGEsc1s2XTsgaW50IGxjPTE7CiAgZWxbMF09MDsgIGVsWzFdPTE7ZWxbMl09MztlbFszXT03O2VsWzRdPTE1O2VsWzVdPTMxO2VsWzZdPTYzO2VsWzddPTEyNztlbFs4XT0yNTU7ZWxbOV09NTExO2VsWzEwXT0xMDIzO2VsWzExXT0yMDQ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