#K9871. Minimum Buses Required

    ID: 39126 Type: Default 1000ms 256MiB

Minimum Buses Required

Minimum Buses Required

In this problem, you are given several bus routes. Each route is represented as a list of bus stops, where each bus stop is denoted by an integer. Two routes are considered identical if they contain the same set of stops regardless of the order in which they appear.

Your task is to determine the minimum number of buses required so that each unique route is served by exactly one bus. Formally, if the sorted representation of route \(R_i\) is identical to that of route \(R_j\), then they are considered the same, and only one bus is required for both.

You can express the solution as follows:

\[ \text{min\_buses} = \left|\{ \text{sorted}(R_i) : i = 1, 2, \dots, n \}\right| \]

inputFormat

The input is read from stdin and is structured as follows:

  • The first line contains an integer \(T\), the number of test cases.
  • For each test case, the first line contains an integer \(R\), indicating the number of bus routes.
  • This is followed by \(R\) lines, each containing a space-separated list of integers representing the bus stops on that route.

outputFormat

For each test case, output a single integer on a new line, representing the minimum number of buses required (i.e. the number of unique routes).

## sample
2
3
1 2 3
3 2 1
1 3 4
2
1 2
2 3
2

2

</p>