#include <stdio.h>
#include <stdlib.h>
long long int row(long long int node)
{
long long int i=1,r=0;
while(i<=node)
{
i*=2;
r++;
}
return r;
}
int main()
{
int q;
long long int a,b,temp,row_a,row_b,c_a,c_b,total_nodes,N;
char in[5];
scanf("%d\n",&q);
int inode=0; //initial node = 0(black), 1(white)
while(q--)
{
scanf("%s",in);
if(in[1]=='i')
{
if(inode)
inode=0;
else
inode=1;
}
else
{
scanf("%lld %lld",&a,&b);
if(a<b)
{
temp=a;
a=b;
b=temp;
}
row_a=row(a)%2; //if 1, then same color as i_node; if 0, then opposite color of i_node;
row_b=row(b)%2;
c_a=c_b=0;
while(row(a)>row(b))
{
a=a/2;
c_a++;
}
while(a!=b)
{
a=a/2;
c_a++;
b=b/2;
c_b++;
}
total_nodes=c_a+c_b+1;
/* row_a=row(a)%2; //if 1, then same color as i_node; if 0, then opposite color of i_node;
row_b=row(b)%2;*/
if(in[1]=='b')
{
if(!inode)//black
{
if(row_a)//black
{
N=(total_nodes/2)+(total_nodes%2);
}
else //white
{
N=(total_nodes/2);
}
}
else//i_node is white
{
if(row_a)//white
{
N=(total_nodes/2);
}
else //black
{
N=(total_nodes/2)+(total_nodes%2);
}
}
}
else if(in[1]='r')
{
if(!inode)//black
{
if(row_a)//black
{
N=(total_nodes/2);
}
else //white
{
N=(total_nodes/2)+(total_nodes%2);
}
}
else//i_node is white
{
if(row_a)//white
{
N=(total_nodes/2)+(total_nodes%2);
}
else //black
{
N=(total_nodes/2);
}
}
}
printf("%lld\n\n",N);
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmxvbmcgbG9uZyBpbnQgcm93KGxvbmcgbG9uZyBpbnQgbm9kZSkKewogICAgbG9uZyBsb25nIGludCBpPTEscj0wOwogICAgd2hpbGUoaTw9bm9kZSkKICAgIHsKICAgICAgICBpKj0yOwogICAgICAgIHIrKzsKICAgIH0KICAgIHJldHVybiByOwp9CmludCBtYWluKCkKewogICAgaW50IHE7CiAgICBsb25nIGxvbmcgaW50IGEsYix0ZW1wLHJvd19hLHJvd19iLGNfYSxjX2IsdG90YWxfbm9kZXMsTjsKICAgIGNoYXIgaW5bNV07CiAgICBzY2FuZigiJWRcbiIsJnEpOwogICAgaW50IGlub2RlPTA7IC8vaW5pdGlhbCBub2RlID0gMChibGFjayksIDEod2hpdGUpCiAgICB3aGlsZShxLS0pCiAgICB7CiAgICAgICAgc2NhbmYoIiVzIixpbik7CiAgICAgICAgaWYoaW5bMV09PSdpJykKICAgICAgICB7CiAgICAgICAgICAgIGlmKGlub2RlKQogICAgICAgICAgICAgICAgaW5vZGU9MDsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgaW5vZGU9MTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgc2NhbmYoIiVsbGQgJWxsZCIsJmEsJmIpOwogICAgICAgICAgICBpZihhPGIpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHRlbXA9YTsKICAgICAgICAgICAgICAgIGE9YjsKICAgICAgICAgICAgICAgIGI9dGVtcDsKICAgICAgICAgICAgfQogICAgICAgICAgICByb3dfYT1yb3coYSklMjsgLy9pZiAxLCB0aGVuIHNhbWUgY29sb3IgYXMgaV9ub2RlOyBpZiAwLCB0aGVuIG9wcG9zaXRlIGNvbG9yIG9mIGlfbm9kZTsKICAgICAgICAgICAgcm93X2I9cm93KGIpJTI7CiAgICAgICAgICAgIGNfYT1jX2I9MDsKICAgICAgICAgICAgd2hpbGUocm93KGEpPnJvdyhiKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYT1hLzI7CiAgICAgICAgICAgICAgICBjX2ErKzsKICAgICAgICAgICAgfQogICAgICAgICAgICB3aGlsZShhIT1iKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBhPWEvMjsKICAgICAgICAgICAgICAgIGNfYSsrOwogICAgICAgICAgICAgICAgYj1iLzI7CiAgICAgICAgICAgICAgICBjX2IrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICB0b3RhbF9ub2Rlcz1jX2ErY19iKzE7Ci8qICAgICAgICAgIHJvd19hPXJvdyhhKSUyOyAvL2lmIDEsIHRoZW4gc2FtZSBjb2xvciBhcyBpX25vZGU7IGlmIDAsIHRoZW4gb3Bwb3NpdGUgY29sb3Igb2YgaV9ub2RlOwogICAgICAgICAgICByb3dfYj1yb3coYiklMjsqLwogICAgICAgICAgICBpZihpblsxXT09J2InKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZighaW5vZGUpLy9ibGFjawogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGlmKHJvd19hKS8vYmxhY2sKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIE49KHRvdGFsX25vZGVzLzIpKyh0b3RhbF9ub2RlcyUyKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZWxzZSAvL3doaXRlCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBOPSh0b3RhbF9ub2Rlcy8yKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlLy9pX25vZGUgaXMgd2hpdGUKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZihyb3dfYSkvL3doaXRlCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBOPSh0b3RhbF9ub2Rlcy8yKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgZWxzZSAvL2JsYWNrCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBOPSh0b3RhbF9ub2Rlcy8yKSsodG90YWxfbm9kZXMlMik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYoaW5bMV09J3InKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZighaW5vZGUpLy9ibGFjawogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGlmKHJvd19hKS8vYmxhY2sKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIE49KHRvdGFsX25vZGVzLzIpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBlbHNlIC8vd2hpdGUKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIE49KHRvdGFsX25vZGVzLzIpKyh0b3RhbF9ub2RlcyUyKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlLy9pX25vZGUgaXMgd2hpdGUKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZihyb3dfYSkvL3doaXRlCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBOPSh0b3RhbF9ub2Rlcy8yKSsodG90YWxfbm9kZXMlMik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGVsc2UgLy9ibGFjawogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgTj0odG90YWxfbm9kZXMvMik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHByaW50ZigiJWxsZFxuXG4iLE4pOwogICAgICAgIH0KCiAgICB9CiAgICByZXR1cm4gMDsKfQo=