public static void main ( String [ ] args ) throws FileNotFoundException {
  Scanner cin = new Scanner ( new File ( "B-large.in" ) ) ;
  PrintStream cout = new PrintStream ( "B-large.out" ) ;
  int _case = 0 ;
  for ( int T = cin . nextInt ( ) ;
  T > 0 ;
  T -- ) {
    _case ++ ;
    int N = cin . nextInt ( ) ;
    int C = cin . nextInt ( ) ;
    int M = cin . nextInt ( ) ;
    int [ ] [ ] a = new int [ C + 1 ] [ N + 1 ] ;
    for ( int i = 0 ;
    i < M ;
    i ++ ) {
      int p = cin . nextInt ( ) ;
      int b = cin . nextInt ( ) ;
      a [ b ] [ p ] ++ ;
    }
    int totalTrains = 0 ;
    for ( int i = 1 ;
    i <= C ;
    i ++ ) {
      int sum = 0 ;
      for ( int j = 1 ;
      j <= N ;
      j ++ ) sum += a [ i ] [ j ] ;
      totalTrains = Math . max ( totalTrains , sum ) ;
    }
    int prefixColSum = 0 ;
    for ( int j = 1 ;
    j <= N ;
    j ++ ) {
      for ( int i = 1 ;
      i <= C ;
      i ++ ) prefixColSum += a [ i ] [ j ] ;
      totalTrains = Math . max ( totalTrains , ( prefixColSum + j - 1 ) / j ) ;
    }
    int promotion = 0 ;
    for ( int j = N ;
    j >= 1 ;
    j -- ) {
      int sum = 0 ;
      for ( int i = 1 ;
      i <= C ;
      i ++ ) sum += a [ i ] [ j ] ;
      int extra = Math . max ( 0 , sum - totalTrains ) ;
      promotion += extra ;
    }
    String ans = "" + totalTrains + " " + promotion ;
    cout . printf ( "Case #%d: %s%n" , _case , ans ) ;
  }
  cin . close ( ) ;
  cout . close ( ) ;
}

public static void main ( String [ ] args ) throws FileNotFoundException { Scanner cin = new Scanner ( new File ( " B - large . in " ) ) ; PrintStream cout = new PrintStream ( " B - large . out " ) ; int _case = 0 ; for ( int T = cin . nextInt ( ) ; T > 0 ; T -- ) { _case ++ ; int N = cin . nextInt ( ) ; int C = cin . nextInt ( ) ; int M = cin . nextInt ( ) ; int [ ] [ ] a = new int [ C + 1 ] [ N + 1 ] ; for ( int i = 0 ; i < M ; i ++ ) { int p = cin . nextInt ( ) ; int b = cin . nextInt ( ) ; a [ b ] [ p ] ++ ; } int totalTrains = 0 ; for ( int i = 1 ; i <= C ; i ++ ) { int sum = 0 ; for ( int j = 1 ; j <= N ; j ++ ) sum += a [ i ] [ j ] ; totalTrains = Math . max ( totalTrains , sum ) ; } int prefixColSum = 0 ; for ( int j = 1 ; j <= N ; j ++ ) { for ( int i = 1 ; i <= C ; i ++ ) prefixColSum += a [ i ] [ j ] ; totalTrains = Math . max ( totalTrains , ( prefixColSum + j - 1 ) / j ) ; } int promotion = 0 ; for ( int j = N ; j >= 1 ; j -- ) { int sum = 0 ; for ( int i = 1 ; i <= C ; i ++ ) sum += a [ i ] [ j ] ; int extra = Math . max ( 0 , sum - totalTrains ) ; promotion += extra ; } String ans = " " + totalTrains + " ▁ " + promotion ; cout . printf ( " Case ▁ # % d : ▁ % s % n " , _case , ans ) ; } cin . close ( ) ; cout . 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 (string_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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (update_expression (identifier))) (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal))) 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 (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)))) (expression_statement (update_expression (array_access array: (array_access array: (identifier) index: (identifier)) index: (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: (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: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (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 (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: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (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: (identifier))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (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: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) 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)))))