#include<iostream>
using namespace std;
int main()
{
long q;
int s=0;
cin>>q;
while(q--)
{
char a[5];
long x,y,p,q,r;
int h1=0,h2=0,high,low;
int red=0,black=0;
cin>>a;
if(a[1]=='i')
{
s=1-s;
continue;
}
cin>>x>>y;
p=x;
q=y;
while(x>0)
{
x>>=1;
h1++;
}
if(p==q)
{
if(h1%2==0)
red++;
else
black++;
if((a[1]=='r' && s==0) || (a[1]=='b' && s==1))
{
cout<<red<<"\n";
continue;
}
if((a[1]=='b' && s==0) || (a[1]=='r' && s==1))
{
cout<<black<<"\n";
continue;
}
}
while(y>0)
{
y>>=1;
h2++;
}
if(h1>h2)
{
high=h1;
low=h2;
}
else
{
high=h2;
low=h1;
r=p;
p=q;
q=r;
}
while(high!=low)
{
p=p/2;
if(high%2==0)
red++;
else
black++;
high--;
}
while(p!=q)
{
p=p/2;
q=q/2;
if(high%2==0)
red+=2;
else
black+=2;
high--;
}
if(high%2==0)
red++;
else
black++;
if((a[1]=='r' && s==0) || (a[1]=='b' && s==1))
{
cout<<red<<"\n";
continue;
}
if((a[1]=='b' && s==0) || (a[1]=='r' && s==1))
{
cout<<black<<"\n";
continue;
}
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKCQoJbG9uZyBxOwoJaW50IHM9MDsKCQoJY2luPj5xOwoJCgl3aGlsZShxLS0pCgl7CgkJY2hhciBhWzVdOwoJCWxvbmcgeCx5LHAscSxyOwoJCWludCBoMT0wLGgyPTAsaGlnaCxsb3c7CgkJaW50IHJlZD0wLGJsYWNrPTA7CgkJCgkJY2luPj5hOwoJCQoJCWlmKGFbMV09PSdpJykKCQl7CgkJCXM9MS1zOwoJCQljb250aW51ZTsKCQl9CgkJCgkJY2luPj54Pj55OwoJCXA9eDsKCQlxPXk7CgkJCgkJd2hpbGUoeD4wKQoJCXsKCQkJeD4+PTE7CgkJCWgxKys7CgkJfQoJCQoJCWlmKHA9P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