from math import log2

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