public static void main ( String [ ] args ) throws IOException {
  Scanner in = new Scanner ( new FileReader ( "Problem3.in" ) ) ;
  PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( "Problem3.out" ) ) ) ;
  int c = in . nextInt ( ) ;
  for ( int cn = 0 ;
  cn < c ;
  cn ++ ) {
    int n = in . nextInt ( ) ;
    int m = in . nextInt ( ) ;
    long x = in . nextInt ( ) ;
    long y = in . nextInt ( ) ;
    long z = in . nextInt ( ) ;
    long sub [ ] = new long [ n ] ;
    BigInteger ans [ ] = new BigInteger [ n ] ;
    long array [ ] = new long [ m ] ;
    for ( int i = 0 ;
    i < m ;
    i ++ ) array [ i ] = in . nextInt ( ) ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) {
      sub [ i ] = array [ i % m ] ;
      array [ i % m ] = ( x * array [ i % m ] + y * ( i + 1 ) ) % z ;
    }
    Arrays . fill ( ans , BigInteger . ONE ) ;
    for ( int i = 1 ;
    i < n ;
    i ++ ) for ( int j = 0 ;
    j < i ;
    j ++ ) {
      if ( sub [ j ] < sub [ i ] ) ans [ i ] = ans [ i ] . add ( ans [ j ] ) ;
    }
    BigInteger sum = BigInteger . ZERO ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) sum = sum . add ( ans [ i ] ) ;
    sum = sum . remainder ( new BigInteger ( "1000000007" ) ) ;
    out . write ( "Case #" + ( cn + 1 ) + ": " + sum . toString ( ) + "\n" ) ;
  }
  in . close ( ) ;
  out . close ( ) ;
}

public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new FileReader ( " Problem3 . in " ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( " Problem3 . out " ) ) ) ; int c = in . nextInt ( ) ; for ( int cn = 0 ; cn < c ; cn ++ ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; long x = in . nextInt ( ) ; long y = in . nextInt ( ) ; long z = in . nextInt ( ) ; long sub [ ] = new long [ n ] ; BigInteger ans [ ] = new BigInteger [ n ] ; long array [ ] = new long [ m ] ; for ( int i = 0 ; i < m ; i ++ ) array [ i ] = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sub [ i ] = array [ i % m ] ; array [ i % m ] = ( x * array [ i % m ] + y * ( i + 1 ) ) % z ; } Arrays . fill ( ans , BigInteger . ONE ) ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) { if ( sub [ j ] < sub [ i ] ) ans [ i ] = ans [ i ] . add ( ans [ j ] ) ; } BigInteger sum = BigInteger . ZERO ; for ( int i = 0 ; i < n ; i ++ ) sum = sum . add ( ans [ i ] ) ; sum = sum . remainder ( new BigInteger ( "1000000007" ) ) ; out . write ( " Case ▁ # " + ( cn + 1 ) + " : ▁ " + sum . toString ( ) + " \n " ) ; } in . close ( ) ; out . close ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))))) (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: (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) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) 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))))) (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))) right: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier)))) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))) right: (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (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: (identifier)) update: (update_expression (identifier)) body: (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 (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) consequence: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))))) (local_variable_declaration type: (type_identifier) 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: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (string_literal)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (string_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))