public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int T = sc . nextInt ( ) ;
  for ( int t = 1 ;
  t <= T ;
  t ++ ) {
    int D = sc . nextInt ( ) ;
    int I = sc . nextInt ( ) ;
    int M = sc . nextInt ( ) ;
    int N = sc . nextInt ( ) ;
    int [ ] A = new int [ N ] ;
    for ( int i = 0 ;
    i < N ;
    i ++ ) A [ i ] = sc . nextInt ( ) ;
    int [ ] DP = new int [ 256 ] ;
    Arrays . fill ( DP , 0 ) ;
    int [ ] CUR = new int [ 256 ] ;
    for ( int at = N - 1 ;
    at >= 0 ;
    at -- ) {
      for ( int i = 0 ;
      i < 1000 ;
      i ++ ) {
        int prev ;
        if ( i % 2 == 0 ) prev = A [ at ] + i / 2 ;
        else prev = A [ at ] - ( i + 1 ) / 2 ;
        if ( prev < 0 || prev >= 256 ) continue ;
        int cost = DP [ prev ] + D ;
        for ( int j = 0 ;
        j < 256 ;
        j ++ ) {
          if ( abs ( j - prev ) <= M || prev == - 1 ) cost = min ( cost , DP [ j ] + abs ( j - A [ at ] ) ) ;
          if ( abs ( j - A [ at ] ) < abs ( A [ at ] - prev ) && ( prev == - 1 || abs ( j - prev ) <= M ) ) cost = min ( cost , CUR [ j ] + I ) ;
        }
        CUR [ prev ] = cost ;
      }
      for ( int j = 0 ;
      j < 256 ;
      j ++ ) DP [ j ] = CUR [ j ] ;
      Arrays . fill ( CUR , 0 ) ;
    }
    int ans = Integer . MAX_VALUE ;
    for ( int i = 0 ;
    i < DP . length ;
    i ++ ) ans = min ( ans , DP [ i ] ) ;
    System . out . format ( "Case #%d: %d\n" , t , ans ) ;
  }
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int D = sc . nextInt ( ) ; int I = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) A [ i ] = sc . nextInt ( ) ; int [ ] DP = new int [ 256 ] ; Arrays . fill ( DP , 0 ) ; int [ ] CUR = new int [ 256 ] ; for ( int at = N - 1 ; at >= 0 ; at -- ) { for ( int i = 0 ; i < 1000 ; i ++ ) { int prev ; if ( i % 2 == 0 ) prev = A [ at ] + i / 2 ; else prev = A [ at ] - ( i + 1 ) / 2 ; if ( prev < 0 || prev >= 256 ) continue ; int cost = DP [ prev ] + D ; for ( int j = 0 ; j < 256 ; j ++ ) { if ( abs ( j - prev ) <= M || prev == - 1 ) cost = min ( cost , DP [ j ] + abs ( j - A [ at ] ) ) ; if ( abs ( j - A [ at ] ) < abs ( A [ at ] - prev ) && ( prev == - 1 || abs ( j - prev ) <= M ) ) cost = min ( cost , CUR [ j ] + I ) ; } CUR [ prev ] = cost ; } for ( int j = 0 ; j < 256 ; j ++ ) DP [ j ] = CUR [ j ] ; Arrays . fill ( CUR , 0 ) ; } int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < DP . length ; i ++ ) ans = min ( ans , DP [ i ] ) ; System . out . format ( " Case ▁ # % d : ▁ % d \n " , t , ans ) ; } }
(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)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) 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: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))) alternative: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (continue_statement)) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) (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 (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (identifier)) right: (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal))) right: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (identifier)))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) (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: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (array_access array: (identifier) index: (identifier))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal) (identifier) (identifier))))))))