public static void main ( String [ ] args ) throws IOException {
  Scanner in = new Scanner ( new FileReader ( "c-small.in" ) ) ;
  PrintWriter out = new PrintWriter ( new FileWriter ( "c-small-out.out" ) ) ;
  final long M = 1000000007 ;
  int T = in . nextInt ( ) ;
  for ( int x = 1 ;
  x <= T ;
  x ++ ) {
    int n = in . nextInt ( ) , m = in . nextInt ( ) , X = in . nextInt ( ) , Y = in . nextInt ( ) , Z = in . nextInt ( ) ;
    int i , j ;
    int [ ] a = new int [ n ] , A = new int [ m ] ;
    long [ ] nr = new long [ n ] ;
    long S = 0 ;
    for ( i = 0 ;
    i < m ;
    i ++ ) {
      A [ i ] = in . nextInt ( ) ;
    }
    for ( i = 0 ;
    i < n ;
    i ++ ) {
      a [ i ] = A [ i % m ] ;
      A [ i % m ] = ( int ) ( ( ( long ) ( ( long ) X * A [ i % m ] + ( long ) Y * ( i + 1 ) ) ) % ( long ) Z ) ;
    }
    nr [ 0 ] = 1 ;
    S = 1 ;
    for ( i = 1 ;
    i < n ;
    i ++ ) {
      nr [ i ] = 1 ;
      for ( j = 0 ;
      j < i ;
      j ++ ) if ( a [ j ] < a [ i ] ) {
        nr [ i ] += nr [ j ] ;
        nr [ i ] %= M ;
      }
      S += nr [ i ] ;
      S %= M ;
    }
    out . printf ( "Case #%d: %d%n" , x , S ) ;
  }
  in . close ( ) ;
  out . close ( ) ;
}

public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new FileReader ( " c - small . in " ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( " c - small - out . out " ) ) ; final long M = 1000000007 ; int T = in . nextInt ( ) ; for ( int x = 1 ; x <= T ; x ++ ) { int n = in . nextInt ( ) , m = in . nextInt ( ) , X = in . nextInt ( ) , Y = in . nextInt ( ) , Z = in . nextInt ( ) ; int i , j ; int [ ] a = new int [ n ] , A = new int [ m ] ; long [ ] nr = new long [ n ] ; long S = 0 ; for ( i = 0 ; i < m ; i ++ ) { A [ i ] = in . nextInt ( ) ; } for ( i = 0 ; i < n ; i ++ ) { a [ i ] = A [ i % m ] ; A [ i % m ] = ( int ) ( ( ( long ) ( ( long ) X * A [ i % m ] + ( long ) Y * ( i + 1 ) ) ) % ( long ) Z ) ; } nr [ 0 ] = 1 ; S = 1 ; for ( i = 1 ; i < n ; i ++ ) { nr [ i ] = 1 ; for ( j = 0 ; j < i ; j ++ ) if ( a [ j ] < a [ i ] ) { nr [ i ] += nr [ j ] ; nr [ i ] %= M ; } S += nr [ i ] ; S %= M ; } out . printf ( " Case ▁ # % d : ▁ % d % n " , x , S ) ; } 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 (string_literal))))))) (local_variable_declaration (modifiers) type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_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))) 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))) 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)) declarator: (variable_declarator name: (identifier))) (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)))) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (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))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (assignment_expression left: (identifier) right: (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (for_statement init: (assignment_expression left: (identifier) right: (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 (cast_expression type: (integral_type) value: (parenthesized_expression (binary_expression left: (binary_expression left: (cast_expression type: (integral_type) value: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier)))) right: (binary_expression left: (cast_expression type: (integral_type) value: (identifier)) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) right: (cast_expression type: (integral_type) value: (identifier))))))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (for_statement init: (assignment_expression left: (identifier) right: (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: (assignment_expression left: (identifier) right: (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: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal) (identifier) (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))