carols-in-morning

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:
__author__ = 'lavee_singh'

from itertools import combinations
def solve(a, n):   # a is array of strings.
	data = []
	for i in range(len(a[0])):
		data.append([])
		for j in range(len(a)):
			if a[j][i] == 'Y':
				data[i].append(j)
	#print data
	for i in range(1, len(data)+1):
		a = combinations(data, i)
		for s in a:
		   # print s
			tem = set()
			for t in s:
				tem = tem.union(set(t))
			if len(tem) >= n: return i
	return n

for _ in range(int(input())):
	n = int(input())
	a = input().split()
	print(solve(a, n))