#include using namespace std; #ifdef _RUTHEN #include #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template using V = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { long long a, b, c, K; cin >> a >> b >> c >> K; map, int> mp; V> his; his.push_back({a, b, c}); mp[{a, b, c}] = 0; for (int t = 1; t <= K; t++) { long long na = (b + c) / 2, nb = (c + a) / 2, nc = (a + b) / 2; show(na, nb, nc); if (mp.count({na, nb, nc})) { int cy = t - mp[{na, nb, nc}]; int rem = (K - t) % cy; auto [ma, mb, mc] = his[mp[{na, nb, nc}] + rem]; a = ma, b = mb, c - mc; break; } else { mp[{na, nb, nc}] = t; his.push_back({na, nb, nc}); a = na, b = nb, c = nc; } show(mp, his); } cout << a + b + c << '\n'; } return 0; }