carols-in-morning-1

When the day begins, it's time to sing carols. Unfortunately, not all the family members know the lyrics to the same carols. Everybody knows at least one, though.
You are given a array of lyrics. The j-th character of the i-th element of lyrics is Y if the i-th person knows the j-th carol, and N if he doesn't. Print the minimal number of carols that must be sung to allow everyone to sing at least once.

Input:-
1st line contains number of testcases and next 2 lines of each testcases contains N and N no. of lyrics. 

Ouput:-
Print the minimal number of carols that must be sung to allow everyone to sing at least once.

SAMPLE INPUT
3
2
YN NY
3
YN YY YN
6
YNN YNY YNY NYY NYY NYN

SAMPLE OUTPUT
2
1
2

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
def get_rem(p,ar):
	n=[]
	for i in ar:
		if i[p]=='N':
			n.append(i)
	return n
t=eval(input())
for i in range(t):
	n=eval(input())
	st=input().split()
	ar=[]
	for k in range(len(st[0])):
		p=k
		i=0
		c=1
		rem=st
		while(i<n):
			rem=get_rem(p%len(st[0]),rem)
			i=n-len(rem)
			if len(rem)>0:
				p+=1
				c+=1
		ar.append(c)
	print(min(ar))


def arr(p,ar):
	n=[]
	for i in ar:
		if i[p]=='N':
			n.append(i)
	return n
t=eval(input())
for i in range(t):
	n=eval(input())
	st=input().split()
	ar=[]
	for k in range(len(st[0])):
		p=k
		i=0
		c=1
		rem=st
		while(i<n):
			rem=arr(p%len(st[0]),rem)
			i=n-len(rem)
			#print rem
			if len(rem)>0:
				p+=1
				c+=1
	#	print c
		ar.append(c)
	print(min(ar))