def main():
    for _ in range(int(input())):
        arr = list(map(int, input().split()))
        count: int = 0
        while True:
            arr.sort(reverse=True)
            if arr[0] >= 1 and arr[1] >= 2:
                arr[0] -= 1
                arr[1] -= 2
                count += 3
            else:
                break
        print(count)


main()
