public static void main ( String [ ] args ) throws IOException {
  BufferedReader buffer = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  String entrada = buffer . readLine ( ) ;
  String ns [ ] = entrada . split ( " " ) ;
  int l = Integer . parseInt ( ns [ 0 ] ) ;
  int d = Integer . parseInt ( ns [ 1 ] ) ;
  int n = Integer . parseInt ( ns [ 2 ] ) ;
  String palavras [ ] = new String [ d + 1 ] ;
  for ( int i = 0 ;
  i < d ;
  i ++ ) {
    palavras [ i ] = buffer . readLine ( ) ;
  }
  for ( int k = 1 ;
  k <= n ;
  k ++ ) {
    List < Set < Character >> conjuntosAceitaveis = new ArrayList < Set < Character >> ( ) ;
    for ( int i = 0 ;
    i < l ;
    i ++ ) {
      conjuntosAceitaveis . add ( new HashSet < Character > ( ) ) ;
    }
    String expressao = buffer . readLine ( ) ;
    int pt = 0 ;
    for ( int i = 0 ;
    i < l ;
    i ++ ) {
      if ( expressao . charAt ( pt ) == '(' ) {
        for ( pt ++ ;
        expressao . charAt ( pt ) != ')' ;
        pt ++ ) {
          conjuntosAceitaveis . get ( i ) . add ( expressao . charAt ( pt ) ) ;
        }
        pt ++ ;
      }
      else {
        conjuntosAceitaveis . get ( i ) . add ( expressao . charAt ( pt ) ) ;
        pt ++ ;
      }
    }
    int cont = 0 ;
    for ( int i = 0 ;
    i < d ;
    i ++ ) {
      boolean pode = true ;
      for ( int j = 0 ;
      j < l ;
      j ++ ) {
        if ( ! conjuntosAceitaveis . get ( j ) . contains ( palavras [ i ] . charAt ( j ) ) ) {
          pode = false ;
          break ;
        }
      }
      if ( pode ) cont ++ ;
    }
    System . out . println ( "Case #" + k + ": " + cont ) ;
  }
}

public static void main ( String [ ] args ) throws IOException { BufferedReader buffer = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String entrada = buffer . readLine ( ) ; String ns [ ] = entrada . split ( " ▁ " ) ; int l = Integer . parseInt ( ns [ 0 ] ) ; int d = Integer . parseInt ( ns [ 1 ] ) ; int n = Integer . parseInt ( ns [ 2 ] ) ; String palavras [ ] = new String [ d + 1 ] ; for ( int i = 0 ; i < d ; i ++ ) { palavras [ i ] = buffer . readLine ( ) ; } for ( int k = 1 ; k <= n ; k ++ ) { List < Set < Character > > conjuntosAceitaveis = new ArrayList < Set < Character > > ( ) ; for ( int i = 0 ; i < l ; i ++ ) { conjuntosAceitaveis . add ( new HashSet < Character > ( ) ) ; } String expressao = buffer . readLine ( ) ; int pt = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( expressao . charAt ( pt ) == ' ( ' ) { for ( pt ++ ; expressao . charAt ( pt ) != ' ) ' ; pt ++ ) { conjuntosAceitaveis . get ( i ) . add ( expressao . charAt ( pt ) ) ; } pt ++ ; } else { conjuntosAceitaveis . get ( i ) . add ( expressao . charAt ( pt ) ) ; pt ++ ; } } int cont = 0 ; for ( int i = 0 ; i < d ; i ++ ) { boolean pode = true ; for ( int j = 0 ; j < l ; j ++ ) { if ( ! conjuntosAceitaveis . get ( j ) . contains ( palavras [ i ] . charAt ( j ) ) ) { pode = false ; break ; } } if ( pode ) cont ++ ; } System . out . println ( " Case ▁ # " + k + " : ▁ " + cont ) ; } }
(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 (field_access object: (identifier) field: (identifier)))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (method_invocation object: (identifier) name: (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 (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (binary_expression left: (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: (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: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_identifier))))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list))))))) (local_variable_declaration type: (type_identifier) 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: (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: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (for_statement init: (update_expression (identifier)) condition: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (update_expression (identifier))))))) (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: (block (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (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 (unary_expression operand: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (break_statement))))) (if_statement condition: (parenthesized_expression (identifier)) consequence: (expression_statement (update_expression (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier)))))))))