
x = int(input())
su = 0
for i in range(x):
    y = list((map(int, input().split())))
    if y[1] == 0:
        print("0")
        continue
    if y[2] > 0:
        y.append(y[2]//2)
        su = min(y[1], y[3])*3
        y[1] = y[1]-(su//3)
    y[1] = y[1]//2
    print((min(y[0], y[1])*3)+su)


