import
java.io.*;
import
java.lang.*;
import
java.util.*;
class
Main {
public
static
void
main(String[] args)
throws
java.lang.Exception
{
String[] Query = { "Black", "Interchange", "Red" };
int
[] start = {
1
,
0
,
3
};
int
[] end = {
5
,
0
,
8
};
Function(Query, start, end);
}
public
static
void
Function(String[] Query,
int
[] start,
int
[] end)
{
boolean
rootBlack =
true
;
for
(
int
i =
0
; i < Query.length; i++) {
long
ans =
0
;
if
(Query[i].equals("Interchange"))
rootBlack = !rootBlack;
else
if
((rootBlack && Query[i].equals("Black"))
|| (!rootBlack
&& Query[i].equals("Red")))
ans = getBlackNodes(start[i], end[i]);
else
ans = getRedNodes(start[i], end[i]);
System.out.println(ans);
}
}
static
long
findLca(
long
x,
long
y)
{
while
(x != y) {
if
(x > y)
x /=
2
;
else
if
(y > x)
y /=
2
;
}
return
x;
}
static
long
blackHeight(
long
n)
{
return
(height(n) +
1
) /
2
;
}
static
long
redHeight(
long
n) {
return
height(n) /
2
; }
static
long
height(
long
n)
{
return
(
long
)(Math.log(n) / Math.log(
2
)) +
1
;
}
static
long
getBlackNodes(
long
x,
long
y)
{
long
lca = findLca(x, y);
long
ans = blackHeight(x) + blackHeight(y)
-
2
* blackHeight(height(lca));
return
(height(lca) %
2
==
1
) ? ans +
1
: ans;
}
static
long
getRedNodes(
long
x,
long
y)
{
long
lca = findLca(x, y);
long
ans = redHeight(x) + redHeight(y)
-
2
* redHeight(lca);
return
(height(lca) %
2
==
0
) ? ans +
1
: ans;
}
}