Under construction

Still being built. Things may change

Teach Me

Interview

Time limit40sMemory limit1024 MB

Summary
Each employee knows up to 5 skills. Count ordered pairs (i, j) where employee i knows some skill that employee j does not.
Level

Medium6 of 10

Topics
Bit manipulation, Combinatorics, Math, Hash map
Solved
No attempts yet

Problem

Here at Google we love teaching new skills to each other. There are N employees at Google, numbered from 1 to N. There are S different skills, numbered from 1 to S. Each employee knows at most 5 different skills.

The i-th employee can mentor the j-th employee if there is a skill that the i-th employee knows and the j-th employee does not know. How many ordered pairs (i, j) are there where the i-th employee can mentor the j-th employee?

Input

The first line of the input gives the number of test cases, T. T test cases follow. The first line of each test case gives the two integers N and S, which are the number of employees and the number of skills respectively.

The next N lines describe the skills that each employee knows. The i-th of these lines begins with an integer Ci, the number of skills the i-th employee knows. Then Ci integers follow on the same line. The j-th of these integers is Aij, meaning that the i-th employee knows the skill Aij.

Output

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 ordered pairs (i, j) where the i-th employee can mentor the j-th employee.

Limits

  • 1 ≤ T ≤ 100.
  • 1 ≤ S ≤ 1000.
  • 1 ≤ Ci ≤ 5 for all i.
  • 1 ≤ Aij ≤ S for all i and j.
  • Aij ≠ Aik for all j ≠ k.

Examples1

  1. Example 1

    Input
    2
    4 100
    4 80 90 100 5
    1 90
    1 80
    3 80 90 100
    3 30
    4 10 11 12 13
    4 10 11 12 13
    5 25 26 27 28 29
    
    Expected output
    Case #1: 7
    Case #2: 4