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(MxM) 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
Sigma Kappa: 2017-08-11 23:37:47

Bitmasks...

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

AC in 1 go:-)

sushantoberoi3: 2016-10-31 07:46:40

bahut tagda question really liked it!! first time missing that check condition...edited the code n AC in 2nd go!!

Aman Singh: 2016-08-14 07:26:01

Problem setter is Naive. It's not mentioned but for case:
1
Y
you have to give output 0 0.

sudip_95: 2016-06-16 08:27:42

it's quite silly! using cin,cout gives TLE. Adding ios::sync_with_stdio(false); gives the same code AC!!!

Ankit Sultana: 2015-06-08 20:29:45

Forgot to note this: "if more than one person matches this criteria, then select the one that comes first ( the one that has the lower ID)."

Archit Jain: 2014-08-30 07:45:24

easy but implementation quite tricky

Gaurav: 2015-02-01 09:58:44

cant find mistake in my code...pls check 9948927

satya hemanth: 2013-08-30 16:24:09

half century :)


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