public static void main ( String [ ] args ) {
  try {
    LineNumberReader lnr = new LineNumberReader ( new InputStreamReader ( System . in ) ) ;
    String line [ ] = lnr . readLine ( ) . trim ( ) . split ( " " ) ;
    final int d = Integer . parseInt ( line [ 1 ] ) ;
    final int n = Integer . parseInt ( line [ 2 ] ) ;
    String word [ ] = new String [ d ] ;
    for ( int i = 0 ;
    i < d ;
    i ++ ) {
      word [ i ] = lnr . readLine ( ) . trim ( ) ;
    }
    for ( int i = 1 ;
    i <= n ;
    i ++ ) {
      String m = lnr . readLine ( ) . trim ( ) . replace ( '(' , '[' ) . replace ( ')' , ']' ) ;
      Pattern pattern = Pattern . compile ( m ) ;
      int count = 0 ;
      for ( String w : word ) {
        if ( pattern . matcher ( w ) . matches ( ) ) {
          count ++ ;
        }
      }
      System . out . println ( "Case #" + i + ": " + count ) ;
    }
  }
  catch ( IOException e ) {
    e . printStackTrace ( ) ;
  }
}

public static void main ( String [ ] args ) { try { LineNumberReader lnr = new LineNumberReader ( new InputStreamReader ( System . in ) ) ; String line [ ] = lnr . readLine ( ) . trim ( ) . split ( " ▁ " ) ; final int d = Integer . parseInt ( line [ 1 ] ) ; final int n = Integer . parseInt ( line [ 2 ] ) ; String word [ ] = new String [ d ] ; for ( int i = 0 ; i < d ; i ++ ) { word [ i ] = lnr . readLine ( ) . trim ( ) ; } for ( int i = 1 ; i <= n ; i ++ ) { String m = lnr . readLine ( ) . trim ( ) . replace ( ' ( ' , ' [ ' ) . replace ( ' ) ' , ' ] ' ) ; Pattern pattern = Pattern . compile ( m ) ; int count = 0 ; for ( String w : word ) { if ( pattern . matcher ( w ) . matches ( ) ) { count ++ ; } } System . out . println ( " Case ▁ # " + i + " : ▁ " + count ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } }
(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 (try_statement 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) dimensions: (dimensions) value: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration (modifiers) 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 (modifiers) 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 (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: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) 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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (character_literal) (character_literal))) name: (identifier) arguments: (argument_list (character_literal) (character_literal))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (identifier) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list))) consequence: (block (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)))))))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))))