public static void main ( final String [ ] args ) {
  final Scanner sc = new Scanner ( System . in ) ;
  final int cases = sc . nextInt ( ) ;
  for ( int cc = 1 ;
  cc <= cases ;
  cc ++ ) {
    final int n = sc . nextInt ( ) ;
    final int m = sc . nextInt ( ) ;
    final long x = sc . nextLong ( ) , y = sc . nextLong ( ) , z = sc . nextLong ( ) ;
    final int [ ] h = new int [ n ] ;
    final int [ ] a = new int [ n ] ;
    for ( int i = 0 ;
    i < m ;
    i ++ ) h [ i ] = sc . nextInt ( ) ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) {
      a [ i ] = h [ i % m ] ;
      h [ i % m ] = ( int ) ( ( x * h [ i % m ] + y * ( i + 1 ) ) % z ) ;
    }
    final int [ ] s = new int [ n ] ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) {
      s [ i ] = 1 ;
      for ( int j = 0 ;
      j < i ;
      j ++ ) if ( a [ j ] < a [ i ] ) s [ i ] = ( s [ i ] + s [ j ] ) % 1000000007 ;
    }
    int count = 0 ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) count = ( count + s [ i ] ) % 1000000007 ;
    System . out . printf ( "Case #%s: %s\n" , cc , count ) ;
  }
  System . out . flush ( ) ;
}

public static void main ( final String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; final int cases = sc . nextInt ( ) ; for ( int cc = 1 ; cc <= cases ; cc ++ ) { final int n = sc . nextInt ( ) ; final int m = sc . nextInt ( ) ; final long x = sc . nextLong ( ) , y = sc . nextLong ( ) , z = sc . nextLong ( ) ; final int [ ] h = new int [ n ] ; final int [ ] a = new int [ n ] ; for ( int i = 0 ; i < m ; i ++ ) h [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = h [ i % m ] ; h [ i % m ] = ( int ) ( ( x * h [ i % m ] + y * ( i + 1 ) ) % z ) ; } final int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = 1 ; for ( int j = 0 ; j < i ; j ++ ) if ( a [ j ] < a [ i ] ) s [ i ] = ( s [ i ] + s [ j ] ) % 1000000007 ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) count = ( count + s [ i ] ) % 1000000007 ; System . out . printf ( " Case ▁ # % s : ▁ % s \n " , cc , count ) ; } System . out . flush ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter (modifiers) type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration (modifiers) 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 (modifiers) 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 (modifiers) type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration (modifiers) type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration (modifiers) type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration (modifiers) type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration (modifiers) 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))))) (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: (cast_expression type: (integral_type) value: (parenthesized_expression (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)))))))) (local_variable_declaration (modifiers) 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: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (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: (identifier)) update: (update_expression (identifier)) body: (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: (binary_expression left: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) right: (decimal_integer_literal)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (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: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) right: (decimal_integer_literal))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal) (identifier) (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list)))))