#include //#include #define elif else if #define ll long long #define vll vector #define vec vector #define embk emplace_back #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep3(i, n, k) for (int i = k; i < (int)(n); i++) #define all(a) a.begin(), a.end() using namespace std; //using namespace atcoder; const ll INF = 1LL << 60; const ll mod = 998244353; void solve() { ll a, b, c, k; cin >> a >> b >> c >> k; k = min(1000LL, k); rep(i, k) { ll d = (b+c) / 2; ll e = (a+c) / 2; ll f = (a+b) / 2; if (d == e && e == f) { cout << d+e+f << endl; return; } else { a = d; b = e; c = f; } } cout << a+b+c << endl; return; } int main() { ll t; cin >> t; rep(i, t) solve(); }