public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int t = sc . nextInt ( ) ;
  while ( t > 0 ) {
    long sum = 0 ;
    int a [ ] = new int [ 3 ] ;
    int b [ ] = new int [ 3 ] ;
    for ( int i = 0 ;
    i < 3 ;
    i ++ ) {
      a [ i ] = sc . nextInt ( ) ;
    }
    for ( int i = 0 ;
    i < 3 ;
    i ++ ) {
      b [ i ] = sc . nextInt ( ) ;
    }
    int min = 0 ;
    min = Math . min ( a [ 1 ] , b [ 0 ] ) ;
    a [ 1 ] -= min ;
    b [ 0 ] -= min ;
    min = Math . min ( a [ 0 ] , b [ 2 ] ) ;
    a [ 0 ] -= min ;
    b [ 2 ] -= min ;
    min = Math . min ( a [ 2 ] , b [ 1 ] ) ;
    a [ 2 ] -= min ;
    b [ 1 ] -= min ;
    sum += 2 * min ;
    sum -= 2 * Math . min ( a [ 1 ] , b [ 2 ] ) ;
    System . out . println ( sum ) ;
    t -- ;
  }
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t > 0 ) { long sum = 0 ; int a [ ] = new int [ 3 ] ; int b [ ] = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < 3 ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } int min = 0 ; min = Math . min ( a [ 1 ] , b [ 0 ] ) ; a [ 1 ] -= min ; b [ 0 ] -= min ; min = Math . min ( a [ 0 ] , b [ 2 ] ) ; a [ 0 ] -= min ; b [ 2 ] -= min ; min = Math . min ( a [ 2 ] , b [ 1 ] ) ; a [ 2 ] -= min ; b [ 1 ] -= min ; sum += 2 * min ; sum -= 2 * Math . min ( a [ 1 ] , b [ 2 ] ) ; System . out . println ( sum ) ; t -- ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)) (array_access array: (identifier) index: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)) (array_access array: (identifier) index: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)) (array_access array: (identifier) index: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)) (array_access array: (identifier) index: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (update_expression (identifier)))))))