SOCIALNE - Possible Friends

no tags 

Josué, one of the undergraduate students in PUCMM, is developing a Social Network, but he is having difficulties in identifying the person that has more possible friends. Two persons are possible friends if they are not friends and they have at least one common friend, for example if person A is friend only to person B, and person B is friend of C, then, A and C are possible friends. You are about to help him in this task. Given the network table, you have to write a program that finds the person that has more possible friends, if more than one person matches this criteria, then select the one that comes first ( the one that has the lower ID).

Input

The first line is T (1 ≤ T ≤ 1,000), the number of test cases, then T test cases follow.

Each test case consists in a 'Y' or 'N' square matrix (M x M) representing the friendship of the network, where M is the number of persons.

Constraints

M (1 ≤ M ≤ 50)

The square matrix has M lines, each line has M characters.

The first line of the matrix corresponds to person 0, the next line to person 1, and so on.

On each line the leftmost character corresponds to person 0, the next character to person 1, and so on.

So if character j of the line i is 'Y', it means that person 'i' is a friend of 'j'.

For each person i, character i of line i will be 'N'.

For each i,j character j of line i will be the same as character i of line j.

Output

For each test case, you have to output one line containing the ID of the person(0-based) that has more possible friends and the number of possible friends this person has, separated by a blank space.

Example

Input:
3
NYN
YNY
NYN
NYYY
YNNY
YNNN
YYNN
NNYNNNN
NNYNNNN
YYNYNNN
NNYNYNN
NNNYNYY
NNNNYNN
NNNNYNN
Output:
0 1
2 2
3 4

hide comments
abhinav1984: 2023-07-18 10:58:07

can be solved with simple bfs. we just have to count no of nodes at distance of 2 from every node and ans is the node with max such nodes.

murtazasaify: 2023-03-14 07:05:19

how to take input here can someone help

atahmid_37: 2021-12-20 09:36:43

FINALLY GOT AC NICE INPUT <3 (3rd attempt) Hint: Simple variation in floyd warshall hehe

sarthak_eddy: 2020-07-16 14:33:27

Nice input format :D

n_o_o_b: 2019-11-08 12:25:12

Does bruteforce work?

hoangvnh: 2019-10-16 19:43:57

AC in 1 go !!! Just a little bit tricky when read input, and then use FloydWarshall and AC :D

prestonbui97: 2018-04-08 07:27:33

AC in 2nd go!!

ameyanator: 2018-03-30 09:47:53

If A is friend of B then B has to be a friend of A right?

Sigma Kappa: 2017-08-11 23:37:47

Bitmasks...

vengatesh15: 2017-01-25 10:32:11

AC in 1 go:-)


Added by:Olson Ortiz
Date:2010-12-09
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C CSHARP C++ 4.3.2 CPP JAVA
Resource:Used in 1st Programming contest PUCMM ACM-ISC 2010 (Dominican Republic)