""" https://yukicoder.me/problems/no/2233 全部偶数だったら、繰り返しそう? 実装適当なのでwa出そう """ import sys from sys import stdin TT = int(stdin.readline()) for loop in range(TT): a,b,c,K = map(int,stdin.readline().split()) dic = {} dic[(a,b,c)] = 0 lis = [a+b+c] for i in range(1,K+1): a,b,c = (b+c)//2 , (c+a)//2 , (a+b)//2 lis.append(a+b+c) tup = (a,b,c) if i == K: print (a+b+c) break if tup in dic: rem = i - dic[tup] print (lis[dic[tup] + rem]) break dic[tup] = i