시간 제한메모리 제한제출정답맞힌 사람정답 비율
20 초 (추가 시간 없음) 1024 MB61392153.846%

문제

A fabric is represented by three properties:

  • Color ($\mathbf{C}$), a string consisting of lowercase letters of the English alphabet, representing the color of the fabric.
  • Durability ($\mathbf{D}$), an integer representing the durability of the fabric.
  • Unique identifier ($\mathbf{U}$), an integer representing the ID of the fabric.

Ada and Charles work at the Kick Start fabric factory. Each day they receive $\mathbf{N}$ fabrics, and one of them has to sort it. They sort it using the following criteria:

  • Ada sorts in lexicographically increasing order by color ($\mathbf{C}$).
  • Charles sorts in ascending order by durability ($\mathbf{D}$).
  • They break ties by sorting in ascending order by the unique identifier ($\mathbf{U}$).

Given $\mathbf{N}$ fabrics, count the number of fabrics which end up in the same position regardless of whether Ada or Charles sort them.

입력

The first line of the input gives the number of test cases, $\mathbf{T}$. $\mathbf{T}$ test cases follow.

Each test case begins with one line consisting of an integer $\mathbf{N}$ denoting the number of fabrics. Then $\mathbf{N}$ lines follow, each line with a string $\mathbf{C_i}$, an integer $\mathbf{D_i}$, and an integer $\mathbf{U_i}$: the color, the durability and the unique identifier of the $i$-th fabric respectively.

출력

For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the number of fabrics which end up in the same position regardless of whether a worker sorts them by color or by durability.

제한

  • $1 \le \mathbf{T} \le 100$.
  • $1 \le$ length of string $\mathbf{C_i}$ $\le 10$.
  • String $\mathbf{C_i}$ consists of only lowercase letters of the English alphabet.
  • No two fabrics have same $\mathbf{U_i}$.

Test Set 1 (4점)

  • $1 \le \mathbf{N} \le 2$.
  • $1 \le \mathbf{D_i} \le 2$.
  • $1 \le \mathbf{U_i} \le 2$.

Test Set 2 (8점)

  • $1 \le \mathbf{N} \le 10^3$.
  • $1 \le \mathbf{D_i} \le 10^2$.
  • $1 \le \mathbf{U_i} \le 10^3$.

예제 입력 1

3
2
blue 2 1
yellow 1 2
2
blue 2 1
brown 2 2
1
red 1 1

예제 출력 1

Case #1: 0
Case #2: 2
Case #3: 1

In Sample Case #1, when sorted by color, the order of fabrics represented by the unique identifier is $1$ and $2$. When sorted by durability, the order of fabrics is $2$ and $1$. Therefore, $0$ fabrics have the same position when sorted by color or durability.

In Sample Case #2, when sorted by color, the order of fabrics represented by the unique identifier is $1$ and $2$. When sorted by durability, the order of fabrics is also $1$ and $2$. Therefore, $2$ fabrics have the same position. Notice that both fabrics have the same durability, so when Charles sorts them he decides that fabric $1$ comes first because it has a smaller identifier.

In Sample Case #3, since there is only $1$ fabric, the position remains the same whether the fabrics are sorted by color or durability.

예제 입력 2

1
5
blue 1 2
green 1 4
orange 2 5
red 3 6
yellow 3 7

예제 출력 2

Case #1: 5

In Sample Case #1, the order is the same for both when sorted by color or durability. So the answer is $5$.

채점 및 기타 정보

  • 예제는 채점하지 않는다.