for _ in range(int(input())): a, b, c, k = map(int, input().split()) L = [a, b, c] L.sort() while k > 0 and not (L[0] == L[1] == L[2]): L = [(L[0] + L[1]) // 2, (L[0] + L[2]) // 2, (L[1] + L[2]) // 2] k -= 1 print(sum(L))