There are N binary strings (consisting of 0s and 1s) in a table. A pair of strings is good if there exists at least one character in common in both strings.
Find the number of good pairs of strings.
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains an integer \(N\) denoting the number of strings on the table.
- Next \(N\) lines of each test case contain the strings present on the table.
Output format
Print \(T\) lines. For each test case:
- Print a single line indicating the number of good pairs of strings.
Constraints
\(1 \leq T \leq 10000\)
\(1 \leq N \leq 100000\)
\(1 \leq Length\ of\ String \leq 5\)
The sum of length over all test cases does not exceed 500000.
First Test Case: String 2 and 3 have character 0 in common
Second test case: All strings have 1 in common so answer is number of pairs, which is 10
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor