按照空座进行优先级排序(相同空座优先级相同)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t -- > 0) {
int a2 = sc.nextInt(), a3 = sc.nextInt(), a4 = sc.nextInt(), b4 = sc.nextInt(), b6 = sc.nextInt();
int ans = 0;
//满座匹配4人寝坐4人桌
int c1 = Math.min(a4, b4);
ans += c1 * 4; a4 -= c1; b4 -= c1;
//满座匹配2x2人寝坐4人桌
int c2 = Math.min(a2 / 2, b4);
ans += c2 * 4; a2 -= c2 * 2; b4 -= c2;
//满座匹配2+4人寝坐6人桌
int c3 = Math.min(Math.min(a2, a4), b6);
ans += c3 * 6; a2 -= c3; a4 -= c3; b6 -= c3;
//满座匹配2x3人寝坐6人桌
int c4 = Math.min(a2 / 3, b6);
ans += c4 * 6; a2 -= c4 * 3; b6 -= c4;
//满座匹配3x2人寝坐6人桌
int c5 = Math.min(a3 / 2, b6);
ans += c5 * 6; a3 -= c5 * 2; b6 -= c5;
//空1座匹配2+3人寝坐6人桌
int c6 = Math.min(Math.min(a2, a3), b6);
ans += c6 * 5; a2 -= c6; a3 -= c6; b6 -= c6;
//空1座匹配3人寝坐4人桌
int c7 = Math.min(a3, b4);
ans += c7 * 3; a3 -= c7; b4 -= c7;
//空2座匹配2x2人寝坐6人桌
int c8 = Math.min(a2 / 2, b6);
ans += c8 * 4; a2 -= c8 * 2; b6 -= c8;
//空2座匹配4人寝坐6人桌
int c9 = Math.min(a4, b6);
ans += c9 * 4; a4 -= c9; b6 -= c9;
//空2座匹配2人寝坐4人桌
int c10 = Math.min(a2, b4);
ans += c10 * 2; a2 -= c10; b4 -= c10;
//空3座匹配3人寝坐6人桌
int c11 = Math.min(a3, b6);
ans += c11 * 3; a3 -= c11; b6 -= c11;
//空4座匹配2人寝坐6人桌
int c12 = Math.min(a2, b6);
ans += c12 * 2; a2 -= c12; b6 -= c12;
System.out.println(ans);
}
}
}