from math import log2

for _ in range(int(input())):
    db, dc, k = 0, 0, 0
    a, b, c = map(int, input().split())
    if b and c:
        dc = int(log2(c))
    if b >= dc:
        b = b - dc
    else:
        k = int(dc/b)
        dc = 0
    if a and b > 1:
        db = int(log2(b))
    print(int(3*(db+dc+k)))