Under construction

Still being built. Things may change

Sort the Fabrics

Interview

Time limit20sMemory limit1024 MB

Summary
Count the fabrics that land in the same position when sorted by color (then ID) and by durability (then ID).
Level

Easy3 of 10

Topics
Sorting, Implementation
Solved
No attempts yet

Problem

Each fabric has three properties:

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

Ada and Charles work at the Kick Start fabric factory. Each day they receive N\mathbf{N} fabrics, and one of them sorts the batch using these rules:

  • Ada sorts in lexicographically increasing order by color (C\mathbf{C}).
  • Charles sorts in ascending order by durability (D\mathbf{D}).
  • Ties are broken by ascending order of the unique identifier (U\mathbf{U}).

Given N\mathbf{N} fabrics, count the fabrics that end up in the same position whether Ada or Charles sorts them.

Input

The first line contains the number of test cases T\mathbf{T}. Then T\mathbf{T} test cases follow.

Each test case begins with a line containing the integer N\mathbf{N}, the number of fabrics. Then N\mathbf{N} lines follow, each with a string Ci\mathbf{C_i}, an integer Di\mathbf{D_i}, and an integer Ui\mathbf{U_i}: the color, durability, and unique identifier of the ii-th fabric.

Output

For each test case, output one line in the form Case #x: y. Here xx is the test case number starting from 1, and yy is the number of fabrics that end up in the same position whether they are sorted by color or by durability.

Limits

  • 1≤T≤1001 \le \mathbf{T} \le 100
  • 1≤1 \le length of Ci≤10\mathbf{C_i} \le 10
  • Ci\mathbf{C_i} consists only of lowercase English letters.
  • No two fabrics have the same Ui\mathbf{U_i}.

Examples2

  1. Example 1

    Input
    3
    2
    blue 2 1
    yellow 1 2
    2
    blue 2 1
    brown 2 2
    1
    red 1 1
    
    Expected output
    Case #1: 0
    Case #2: 2
    Case #3: 1
    
  2. Example 2

    Input
    1
    5
    blue 1 2
    green 1 4
    orange 2 5
    red 3 6
    yellow 3 7
    
    Expected output
    Case #1: 5