#include<bits/stdc++.h>
using namespace std;
int q;
int aa,aaa,aaaa,bbbb,bbbbbb;
int tot;
int main() {
cin>>q;
while(q--) {
cin>>aa>>aaa>>aaaa>>bbbb>>bbbbbb;
while(bbbbbb&&aaa) {
bbbbbb--;
aaa--;
tot+=3;
}
while(bbbbbb&&aaaa) {
bbbbbb--;
aaaa--;
tot+=4;
}while(bbbb&&aa) {
bbbb--;
aa--;
tot+=2;
}
while(bbbb&&aaa) {
bbbb--;
aaa--;
tot+=3;
}
while(bbbb&&aaaa) {
bbbb--;
aaaa--;
tot+=4;
}
while(bbbbbb&&aa) {
bbbbbb--;
aa--;
tot+=2;
}
cout<<tot<<endl;
tot=0;
}
return 0;
}