#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000005 #define Inf64 4000000000000000001LL int main(){ int _t; cin>>_t; rep(_,_t){ vector a(3),b(3); rep(i,3)cin>>a[i]; rep(i,3)cin>>b[i]; { mcf_graph g(8); rep(i,3){ rep(j,3){ int cost = 0; if((i+1)%3==j)cost = 1; g.add_edge(i,j+3,100000000,cost); } } rep(i,3){ g.add_edge(6,i,a[i],0); g.add_edge(i+3,7,b[i],0); } cout<