#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using Graph = vector >; using mint = modint998244353; const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e+18; #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP2(i, s, n) for (int i = (s); i < (int)(n); i++) #define REPB(i,n) for(int i = n-1; (int)i >= 0; --i) #define FOREACH(x,a) for(auto& (x) : (a) #define YESNO(T) if(T){cout<<"YES"< #define VL vector #define VS vector #define VC vector #define VVI vector > #define VVL vector > #define VVC vector > #define VPII vector > #define VPLL vector > #define VPSI vector > template inline void printVec(std::vector v){ REP(i,v.size()){ if(i) std::cout << " "; std::cout << v[i]; } std::cout << std::endl; } template bool chmax(T& a,T b) { if(a < b) { a = b; return true; } return false; } template bool chmin(T& a,T b) { if(a > b) { a = b; return true; } return false; } ll gcd(ll a, ll b){ if(a % b == 0) return b; else return gcd(b, a % b); } ll lcm(ll a, ll b){ return a * b / gcd(a,b); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int t; cin >> t; REP(i,t){ ull a,b,c,k; cin >> a >> b >> c >> k; bool flg = 0; if(k == 0){ cout << a + b + c << endl; continue; } if((a == 0 && b == 1 && c == 1) || (a == 1 && b == 1 && c == 0) || (a == 1 && b == 0 && c == 1)){ if(k <= 1) cout << 1 << endl; else cout << 0 << endl; continue; } int cnt = 0; if((a + b) % 2 == 0) cnt++; if((b + c) % 2 == 0) cnt++; if((c + a) % 2 == 0) cnt++; if(cnt == 0 || cnt == 3){ cout << a + b + c << endl; } else cout << a + b + c - 1 << endl; } return 0; }