spoj#IITKWPCH. Find Number Of Pair of Friends
Find Number Of Pair of Friends
You are given n numbers. Any two number are called friends if they have some digit common. eg. (11, 12) and (15, 4561) are friends but (33, 556) is not.
Find out no of pairs which are friends.
(Formally speaking Let us assume the n numbers be are stored in array a[]. You have to find out number of i and j pairs such that i < j and a[i] and a[j] are friends.).
Input
T : no of test cases (T >= 1 && T <= 7)
For each test case, you will be given two lines, first line will contain n <= 10^6
then in next n line each line will contain a single integer representing a[i] (a[i] >= 1 && a[i] <= 10^18)
Output
For every test case print a line
containing number of such pairs as mentioned in the problem statement.
Example
Input: 4
2
12 13
3
10 12 24
3
5 6 7
4
10 11 211 3
Output:
1
2
0
3