import java.util.Scanner; public class Main { public static void main(String[] args) { new Main(); } public Main() { try (Scanner sc = new Scanner(System.in)) { int T = sc.nextInt(); while((T--) > 0) { int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(); long X = sc.nextInt(), Y = sc.nextInt(), Z = sc.nextInt(); int a, b, c; long INF = 2_000_000_000_000_000_000L; long cost = INF; if (C > 1 && B > 2) { // 1. A 1 && B > 2) { // 2. C 1 && C > 2) { // 3. B 1 && A > 2) { // 4. B