#K78502. Unique Product Pairs
Unique Product Pairs
Unique Product Pairs
In this problem, you are given multiple test cases. Each test case consists of a number of transactions, where each transaction is a line containing several product names separated by spaces. Your task is to determine how many unique pairs of products have been bought together in each test case. A unique pair is defined as a combination of two distinct products that appear together in any transaction, regardless of the order in which they appear.
For example, if a transaction is "apple banana orange", then the possible unique pairs are ( (apple, banana), (apple, orange), (banana, orange) ), so the answer would be 3 for that test case.
inputFormat
The input is read from standard input (stdin) and consists of several lines. The first line contains an integer ( T ), the number of test cases. For each test case, the first line contains an integer ( N ), the number of transactions. The next ( N ) lines each contain a transaction represented by space-separated product names.
outputFormat
For each test case, output a single integer on a new line representing the number of unique product pairs bought together at least once.## sample
2
3
apple banana
banana orange
apple orange
2
book pen
pen pencil pen
3
3
</p>