Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters 'a', 'b', 'c', 'd' and 'e'!

To compose a story, Stephen wrote out $n$ words consisting of the first $5$ lowercase letters of the Latin alphabet. He wants to select the maximum number of words to make an interesting story.

Let a story be a sequence of words that are not necessarily different. A story is called interesting if there exists a letter which occurs among all words of the story more times than all other letters together.

For example, the story consisting of three words "bac", "aaada", "e" is interesting (the letter 'a' occurs $5$ times, all other letters occur $4$ times in total). But the story consisting of two words "aba", "abcde" is not (no such letter that it occurs more than all other letters in total).

You are given a sequence of $n$ words consisting of letters 'a', 'b', 'c', 'd' and 'e'. Your task is to choose the maximum number of them to make an interesting story. If there's no way to make a non-empty story, output $0$.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 5000$) — the number of test cases. Then $t$ test cases follow.

The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of the words in the sequence. Then $n$ lines follow, each of them contains a word — a non-empty string consisting of lowercase letters of the Latin alphabet. The words in the sequence may be non-distinct (i. e. duplicates are allowed). Only the letters 'a', 'b', 'c', 'd' and 'e' may occur in the words.

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$; the sum of the lengths of all words over all test cases doesn't exceed $4 \cdot 10^5$.


-----Output-----

For each test case, output the maximum number of words that compose an interesting story. Print 0 if there's no way to make a non-empty interesting story.


-----Examples-----

Input
6
3
bac
aaada
e
3
aba
abcde
aba
2
baba
baba
4
ab
ab
c
bc
5
cbdca
d
a
d
e
3
b
c
ca
Output
3
2
0
2
3
2


-----Note-----

In the first test case of the example, all $3$ words can be used to make an interesting story. The interesting story is "bac aaada e".

In the second test case of the example, the $1$-st and the $3$-rd words can be used to make an interesting story. The interesting story is "aba aba". Stephen can't use all three words at the same time.

In the third test case of the example, Stephen can't make a non-empty interesting story. So the answer is $0$.

In the fourth test case of the example, Stephen can use the $3$-rd and the $4$-th words to make an interesting story. The interesting story is "c bc".

Difficulty: MEDIUM
Tags: String algorithms

Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
from itertools import accumulate
for _ in range(int(input())):
	r = {'a': [], 'b': [], 'c': [], 'd': [], 'e': []}
	for _ in range(int(input())):
		s = input()
		for key in r:
			r[key].append(2 * s.count(key) - len(s))
	for key in r:
		if sum(r[key]) > 0:
			r[key] = len(r[key])
		else:
			r[key] = sum((x > 0 for x in accumulate(sorted(r[key], reverse=True))))
	print(max(r.values()))


import sys
cin = int(sys.stdin.readline().strip())
for testcase in range(cin):
	cin1 = int(sys.stdin.readline().strip())
	words = []
	for i in range(cin1):
		words.append(sys.stdin.readline().strip())
	(ans1, ans2, ans3, ans4, ans5) = (0, 0, 0, 0, 0)
	(x1, x2, x3, x4, x5) = (0, 0, 0, 0, 0)
	(la, lb, lc, ld, le) = ([], [], [], [], [])
	for i in words:
		d = {'a': 0, 'other': 0}
		for j in i:
			if j == 'a':
				d[j] += 1
			else:
				d['other'] += 1
		la.append(d['a'] - d['other'])
	la.sort(reverse=True)
	for i in la:
		if ans1 + i <= 0:
			break
		else:
			ans1 += i
			x1 += 1
	for i in words:
		d = {'b': 0, 'other': 0}
		for j in i:
			if j == 'b':
				d[j] += 1
			else:
				d['other'] += 1
		lb.append(d['b'] - d['other'])
	lb.sort(reverse=True)
	for i in lb:
		if ans2 + i <= 0:
			break
		else:
			ans2 += i
			x2 += 1
	for i in words:
		d = {'c': 0, 'other': 0}
		for j in i:
			if j == 'c':
				d[j] += 1
			else:
				d['other'] += 1
		lc.append(d['c'] - d['other'])
	lc.sort(reverse=True)
	for i in lc:
		if ans3 + i <= 0:
			break
		else:
			ans3 += i
			x3 += 1
	for i in words:
		d = {'d': 0, 'other': 0}
		for j in i:
			if j == 'd':
				d[j] += 1
			else:
				d['other'] += 1
		ld.append(d['d'] - d['other'])
	ld.sort(reverse=True)
	for i in ld:
		if ans4 + i <= 0:
			break
		else:
			ans4 += i
			x4 += 1
	for i in words:
		d = {'e': 0, 'other': 0}
		for j in i:
			if j == 'e':
				d[j] += 1
			else:
				d['other'] += 1
		le.append(d['e'] - d['other'])
	le.sort(reverse=True)
	for i in le:
		if ans5 + i <= 0:
			break
		else:
			ans5 += i
			x5 += 1
	print(max(x1, x2, x3, x4, x5))


t = int(input())

def aux(a):
	a = sorted(a, key=lambda x: x[0] - x[1], reverse=True)
	if a[0][0] <= a[0][1]:
		return 0
	res = 1
	cur_sum = a[0][0]
	rem_sum = a[0][1]
	for i in range(1, len(a)):
		if cur_sum + a[i][0] > rem_sum + a[i][1]:
			cur_sum += a[i][0]
			rem_sum += a[i][1]
			res += 1
	return res
for _ in range(t):
	n = int(input())
	words = []
	for i in range(n):
		words.append(input())
	hash_words = []
	for word in words:
		h_word = [0, 0, 0, 0, 0]
		for j in range(len(word)):
			h_word[ord(word[j]) - ord('a')] += 1
		hash_words.append(h_word)
	res = 0
	for i in range(5):
		a = []
		for j in range(n):
			a.append((hash_words[j][i], sum(hash_words[j]) - hash_words[j][i]))
		cur_res = aux(a)
		res = max(cur_res, res)
	print(res)


from io import BytesIO, IOBase
import sys
import math
import os
import heapq
from collections import defaultdict, deque
from math import ceil
from bisect import bisect_left, bisect_left
from time import perf_counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def mint():
	return map(int, input().split())

def mfloat():
	return map(float, input().split())

def intin():
	return int(input())

def score(s, letter):
	c = s.count(letter)
	return c - (len(s) - c)

def solve():
	strings = [input() for i in range(int(input()))]
	ans = 0
	for letter in 'abcde':
		scores = sorted(map(lambda s: score(s, letter), strings), reverse=True)
		total = 0
		possible = 0
		for i in scores:
			total += i
			if total > 0:
				possible += 1
			else:
				break
		ans = max(ans, possible)
	print(ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
start_time = perf_counter()
main()
print(perf_counter() - start_time, file=sys.stderr)


for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	c = []
	d = []
	e = []
	for i in range(n):
		arr = list(input())
		l = len(arr)
		cnt = [0, 0, 0, 0, 0]
		for j in arr:
			cnt[ord(j) - 97] += 1
		a.append(cnt[0] * 2 - l)
		b.append(cnt[1] * 2 - l)
		c.append(cnt[2] * 2 - l)
		d.append(cnt[3] * 2 - l)
		e.append(cnt[4] * 2 - l)
	a.sort(reverse=True)
	b.sort(reverse=True)
	c.sort(reverse=True)
	d.sort(reverse=True)
	e.sort(reverse=True)
	a_c = a[0]
	b_c = b[0]
	c_c = c[0]
	d_c = d[0]
	e_c = e[0]
	ans = 0
	if a_c > 0:
		for i in range(1, n):
			a_c += a[i]
			if a_c < 1:
				ans = max(i, ans)
				break
	if b_c > 0:
		for i in range(1, n):
			b_c += b[i]
			if b_c < 1:
				ans = max(i, ans)
				break
	if c_c > 0:
		for i in range(1, n):
			c_c += c[i]
			if c_c < 1:
				ans = max(i, ans)
				break
	if d_c > 0:
		for i in range(1, n):
			d_c += d[i]
			if d_c < 1:
				ans = max(i, ans)
				break
	if e_c > 0:
		for i in range(1, n):
			e_c += e[i]
			if e_c < 1:
				ans = max(i, ans)
				break
	if a_c >= 1 or b_c >= 1 or c_c >= 1 or (d_c >= 1) or (e_c >= 1):
		ans = n
	print(ans)


from collections import Counter
T = int(input())
li = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}
for _ in range(T):
	N = int(input())
	H = [[] for _ in range(5)]
	all_H = [0] * 5
	for i in range(N):
		S = input()
		X = [0] * 5
		for j in range(len(S)):
			X[li[S[j]]] += 1
			all_H[li[S[j]]] += 1
		diff = [0] * 5
		for j in range(5):
			cnt_a_letter = X[j]
			cnt_others = sum(X) - cnt_a_letter
			H[j].append(cnt_a_letter - cnt_others)
	ans = 0
	for i in range(5):
		isOK = False
		arr = H[i]
		arr.sort()
		tmp = N
		cnt_a_letter = all_H[i]
		cnt_others = sum(all_H) - cnt_a_letter
		R = cnt_others - cnt_a_letter
		for j in range(N):
			if R < 0:
				isOK = True
				break
			if arr[j] >= 0:
				break
			R += arr[j]
			tmp -= 1
		if isOK:
			ans = max(ans, tmp)
	print(ans)


import os, sys, math
from io import BytesIO, IOBase
ip = lambda : input()
it = lambda : int(input())
ma = lambda : map(int, input().split(' '))
li = lambda : list(map(int, input().split(' ')))
mod = 10 ** 9 + 7

def solve(a, s, n):
	count = 0
	z = []
	for i in range(n):
		c = s[i].count(a)
		l = len(s[i])
		z.append(2 * c - l)
	z.sort(reverse=True)
	count = 0
	sum = 0
	i = 0
	while i < n:
		sum += z[i]
		i += 1
		if sum < 1:
			break
		count += 1
	return count

def main():
	for _ in range(int(input())):
		n = it()
		s = []
		for i in range(n):
			x = ip()
			s.append(x)
		Max = 0
		for i in range(5):
			z = solve(chr(97 + i), s, n)
			if z > Max:
				Max = z
		print(Max)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import defaultdict
import sys, string
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		s = input().strip()
		x = [0] * 5
		for j in s:
			x[ord(j) - 97] += 1
		l.append(x)
	g_ans = 0
	for j in range(5):
		l.sort(key=lambda x: -x[j])
		p = []
		for i in l:
			p.append(2 * i[j] - sum(i))
		p.sort(reverse=True)
		d = 0
		if p[0] > 0:
			ans = p[0]
			d = 1
			for i in range(1, len(p)):
				ans += p[i]
				if ans > 0:
					d = i + 1
		g_ans = max(g_ans, d)
	print(g_ans)


T = int(input())
for testcase in range(1, T + 1):
	n = int(input())
	w = []
	wc = []
	c = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
	for _ in range(n):
		word = input()
		w.append(word)
		nr = []
		s = len(word)
		for k in c:
			x = word.count(k)
			c[k] += x
			nr.append(x - (s - x))
		wc.append(nr)
	best = 0
	for (index, letter) in enumerate(c):
		wc.sort(key=lambda x: -x[index])
		count = 0
		mysum = 0
		for w in wc:
			x = w[index]
			if mysum + x > 0:
				count += 1
				mysum += x
			if count > best:
				best = count
	print(best)


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	numCollections = []
	letters = ['a', 'b', 'c', 'd', 'e']
	for l in letters:
		numCollections.append([])
	for j in range(n):
		word = input()
		mostCommon = Counter(word)
		for l in range(len(letters)):
			numCollections[l].append(mostCommon[letters[l]] - len(word) / 2)
	for l in numCollections:
		l.sort(reverse=True)
	maxTotal = 0
	for l in numCollections:
		counter = 0
		total = 0
		for num in l:
			total += num
			if total <= 0:
				break
			else:
				counter += 1
		maxTotal = max(maxTotal, counter)
	print(maxTotal)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = [[0 for i in range(5)] for i in range(n)]
	for i in range(n):
		a = input()
		for j in a:
			ans[i][97 - ord(j)] += 1
	now = []
	x = 0
	y = 0
	k = 0
	for i in range(n):
		a = ans[i][0]
		b = sum(ans[i][1:])
		if a > b:
			x += a
			y += b
			k += 1
		else:
			now.append(b - a)
	now.sort()
	for i in now:
		if i + y < x:
			y = y + i
			k += 1
		else:
			break
	now = []
	x = 0
	y = 0
	k1 = 0
	for i in range(n):
		a = ans[i][1]
		b = sum(ans[i]) - ans[i][1]
		if a > b:
			x += a
			y += b
			k1 += 1
		else:
			now.append(b - a)
	now.sort()
	for i in now:
		if i + y < x:
			y = y + i
			k1 += 1
		else:
			break
	now = []
	x = 0
	y = 0
	k2 = 0
	for i in range(n):
		a = ans[i][2]
		b = sum(ans[i]) - ans[i][2]
		if a > b:
			x += a
			y += b
			k2 += 1
		else:
			now.append(b - a)
	now.sort()
	for i in now:
		if i + y < x:
			y = y + i
			k2 += 1
		else:
			break
	now = []
	x = 0
	y = 0
	k3 = 0
	for i in range(n):
		a = ans[i][3]
		b = sum(ans[i]) - ans[i][3]
		if a > b:
			x += a
			y += b
			k3 += 1
		else:
			now.append(b - a)
	now.sort()
	for i in now:
		if i + y < x:
			y = y + i
			k3 += 1
		else:
			break
	now = []
	x = 0
	y = 0
	k4 = 0
	for i in range(n):
		a = ans[i][4]
		b = sum(ans[i]) - ans[i][4]
		if a > b:
			x += a
			y += b
			k4 += 1
		else:
			now.append(b - a)
	now.sort()
	for i in now:
		if i + y < x:
			y = y + i
			k4 += 1
		else:
			break
	print(max(k, k1, k2, k3, k4))


t = int(input())
for task in range(t):
	n = int(input())
	words = []
	for i in range(5):
		words.append([0] * n)
	for i in range(n):
		s = input()
		for j in s:
			words[ord(j) - ord('a')][i] += 2
		for w in words:
			w[i] -= len(s)
	res = 0
	for w in words:
		w.sort(reverse=1)
		if w[0] <= 0:
			continue
		tmpRes = 1
		tmpSum = w[0]
		for i in range(1, n):
			if tmpSum > -w[i]:
				tmpSum += w[i]
				tmpRes += 1
		if tmpRes > res:
			res = tmpRes
	print(res)


import sys, time, os, collections
for t in range(int(input())):
	N = int(input())
	lis = []
	for i in range(N):
		S = sys.stdin.readline().strip()
		lis.append(S)
	D = collections.defaultdict(int)
	T = collections.defaultdict(int)
	conv = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}
	for i in range(N):
		for j in lis[i]:
			D[i, j] += 1
			T[i] += 1
	mx = -1 << 69
	for alpha in range(1, 6):
		nls = []
		tot = 0
		for i in range(N):
			nls.append((D[i, conv[alpha]], T[i] - D[i, conv[alpha]]))
		nls.sort(reverse=True, key=lambda x: x[0] - x[1])
		curl = 0
		curr = 0
		for i in nls:
			curl += i[0]
			curr += i[1]
			if curl > curr:
				tot += 1
		mx = max(mx, tot)
	print(mx)


import heapq, math
from collections import defaultdict, deque
from os import getcwd
from functools import cmp_to_key
import sys, os.path
if os.path.exists('C:/Users/Dhanush/Desktop/cp/input.txt'):
	sys.stdout = open('C:/Users/Dhanush/Desktop/cp/output.txt', 'w')
	sys.stdin = open('C:/Users/Dhanush/Desktop/cp/input.txt', 'r')
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	n = int(input())
	(al, bl, cl, dl, el) = ([], [], [], [], [])
	for i in range(n):
		s = input().strip()
		cur = [0, 0, 0, 0, 0]
		for j in s:
			pos = ord(j) - ord('a')
			cur[pos] += 1
		al.append(cur[0] - (cur[1] + cur[2] + cur[3] + cur[4]))
		bl.append(cur[1] - (cur[0] + cur[2] + cur[3] + cur[4]))
		cl.append(cur[2] - (cur[1] + cur[0] + cur[3] + cur[4]))
		dl.append(cur[3] - (cur[1] + cur[2] + cur[0] + cur[4]))
		el.append(cur[4] - (cur[1] + cur[2] + cur[3] + cur[0]))
	al.sort(reverse=True)
	bl.sort(reverse=True)
	cl.sort(reverse=True)
	dl.sort(reverse=True)
	el.sort(reverse=True)
	ans = 0
	count = 0
	cur = 0
	for i in al:
		cur += i
		if cur > 0:
			count += 1
		else:
			break
	ans = max(ans, count)
	count = 0
	cur = 0
	for i in bl:
		cur += i
		if cur > 0:
			count += 1
		else:
			break
	ans = max(ans, count)
	count = 0
	cur = 0
	for i in cl:
		cur += i
		if cur > 0:
			count += 1
		else:
			break
	ans = max(ans, count)
	count = 0
	cur = 0
	for i in dl:
		cur += i
		if cur > 0:
			count += 1
		else:
			break
	ans = max(ans, count)
	count = 0
	cur = 0
	for i in el:
		cur += i
		if cur > 0:
			count += 1
		else:
			break
	ans = max(ans, count)
	print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	count = [Counter(input()) for x in range(n)]
	max_words = 0
	for letter in 'abcde':
		letter_dif = sorted(map(lambda c: c[letter] * 2 - sum(c.values()), count), reverse=True)
		total = 0
		c = 0
		for i in letter_dif:
			total += i
			if total <= 0:
				break
			c += 1
		max_words = max(max_words, c)
	print(max_words)


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	b = []
	c = []
	d = []
	e = []
	for j in range(n):
		s = input()
		a_ = s.count('a')
		b_ = s.count('b')
		c_ = s.count('c')
		d_ = s.count('d')
		e_ = s.count('e')
		a.append(a_ - b_ - c_ - d_ - e_)
		b.append(b_ - a_ - c_ - d_ - e_)
		c.append(c_ - a_ - b_ - d_ - e_)
		d.append(d_ - a_ - b_ - c_ - e_)
		e.append(e_ - a_ - b_ - c_ - d_)
	a.sort()
	b.sort()
	c.sort()
	d.sort()
	e.sort()
	a.reverse()
	b.reverse()
	c.reverse()
	d.reverse()
	e.reverse()
	if sum(a) > 0 or sum(b) > 0 or sum(c) > 0 or (sum(d) > 0) or (sum(e) > 0):
		print(n)
	elif a[0] <= 0 and b[0] <= 0 and (c[0] <= 0) and (d[0] <= 0) and (e[0] <= 0):
		print(0)
	else:
		ma = 0
		s = 0
		i = 0
		while s + a[i] > 0:
			s += a[i]
			i += 1
		ma = max(ma, i)
		s = 0
		i = 0
		while s + b[i] > 0:
			s += b[i]
			i += 1
		ma = max(ma, i)
		s = 0
		i = 0
		while s + c[i] > 0:
			s += c[i]
			i += 1
		ma = max(ma, i)
		s = 0
		i = 0
		while s + d[i] > 0:
			s += d[i]
			i += 1
		ma = max(ma, i)
		s = 0
		i = 0
		while s + e[i] > 0:
			s += e[i]
			i += 1
		ma = max(ma, i)
		print(ma)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	ls = ['a', 'b', 'c', 'd', 'e']
	pwrt = [[], [], [], [], []]
	for i in range(n):
		s = input()
		q = len(s)
		c = Counter(s)
		for (i, x) in enumerate(ls):
			pwrt[i].append(2 * c[x] - q)
	h = set()
	for i in range(5):
		pwrt[i].sort(reverse=True)
		(j, s) = (0, 0)
		while j < n and s + pwrt[i][j] > 0:
			s += pwrt[i][j]
			j += 1
		h.add(j)
	print(max(h))


def word_to_vec(word):
	t = []
	for letter in 'abcde':
		t.append(word.count(letter))
	sum_ = sum(t)
	return [2 * tt - sum_ for tt in t]
for _ in range(int(input())):
	S = []
	for _ in range(int(input())):
		S.append(word_to_vec(input()))
	RES = []
	for t in zip(*S):
		t = sorted(t, reverse=True)
		if t[0] <= 0:
			continue
		t_sum = t[0]
		i = 1
		while i < len(t) and t_sum + t[i] > 0:
			t_sum += t[i]
			i += 1
		RES.append(i)
	print(max(RES + [0]))


num_cases = int(input())
letters = ['a', 'b', 'c', 'd', 'e']
for _ in range(num_cases):
	num_words = int(input())
	words = [input() for x in range(num_words)]
	ans = 0
	for letter in letters:
		counts = [2 * word.count(letter) - len(word) for word in words]
		counts.sort(reverse=True)
		tot_sum = 0
		for (num, val) in enumerate(counts):
			if tot_sum + val > 0:
				tot_sum += val
			else:
				ans = max(num, ans)
				break
			if num == len(counts) - 1:
				ans = len(counts)
	print(ans)


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd
import bisect
import copy
from itertools import combinations
import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	li = ['a', 'b', 'c', 'd', 'e']
	n = int(input())
	arr = []
	for i in range(n):
		s = input()
		arr.append(s)
	maxi = -1
	for i in range(len(li)):
		ra = []
		(fin, rem) = (0, 0)
		arr1 = []
		for j in range(n):
			st = arr[j]
			cnt = 0
			for k in range(len(st)):
				if st[k] == li[i]:
					cnt += 1
			if cnt > len(st) - cnt:
				fin += 1
				rem += 2 * cnt - len(st)
			else:
				arr1.append(len(st) - 2 * cnt)
		arr1.sort()
		for i in range(len(arr1)):
			rem -= arr1[i]
			if rem > 0:
				fin += 1
			else:
				break
		maxi = max(maxi, fin)
	print(maxi)


for _ in range(int(input())):
	n = int(input())
	li = []
	m = 0
	for _ in range(n):
		s = input()
		c = [0, 0, 0, 0, 0]
		for i in s:
			c[ord(i) - 97] += 1
		li.append(c)
	for i in range(5):
		li.sort(key=lambda c: 2 * c[i] - sum(c), reverse=True)
		c1 = c2 = 0
		for j in range(n):
			c1 += li[j][i]
			c2 += sum(li[j])
			if 2 * c1 <= c2:
				m = max(m, j)
				break
		else:
			m = max(m, n)
	print(m)


def solve(arr, j):
	am = 0
	c = 0
	marr = []
	for el in arr:
		k = 2 * el[j] - sum(el)
		if k > 0:
			am += 1
			c += k
		else:
			marr.append(k)
	marr.sort(reverse=True)
	ind = 0
	while c > 0 and ind < len(marr):
		am += 1
		c += marr[ind]
		ind += 1
	if c > 0:
		return am
	else:
		return max(am - 1, 0)
t = int(input())
for i in range(t):
	n = int(input())
	words = []
	for j in range(n):
		words.append(input())
	array = [[0, 0, 0, 0, 0] for j in range(n)]
	for j in range(n):
		for k in words[j]:
			if k == 'a':
				array[j][0] += 1
			elif k == 'b':
				array[j][1] += 1
			elif k == 'c':
				array[j][2] += 1
			elif k == 'd':
				array[j][3] += 1
			else:
				array[j][4] += 1
	res = [0, 0, 0, 0, 0]
	for j in range(5):
		res[j] += solve(array, j)
	print(max(res))


from collections import Counter

def main():
	num = int(input())
	strings = []
	for _ in range(num):
		inp = input()
		strings.append(inp)
	counter = [Counter(w) for w in strings]

	def solve(ch):
		seq = sorted(range(num), key=lambda x: (counter[x][ch] - (len(strings[x]) - counter[x][ch]), -len(strings[x])), reverse=True)
		ans = remchars = remscore = 0
		for i in seq:
			cnt = counter[i][ch]
			remchars += cnt
			remscore += len(strings[i]) - cnt
			if remchars <= remscore:
				return ans
			ans += 1
		return ans
	ans = 0
	for c in 'abcde':
		ans = max(ans, solve(c))
	return ans
Test = int(input())
for _ in range(Test):
	ans = main()
	print(ans)


def f(S):
	counts = [0, 0, 0, 0, 0]
	for c in S:
		i = ord(c) - ord('a')
		counts[i] += 1
	return counts

def g(C, i):
	return 2 * C[i] - sum(C)

def process(A):
	A2 = [f(S) for S in A]
	my_max = 0
	for i in range(5):
		A3 = [g(C, i) for C in A2]
		A3 = sorted(A3, reverse=True)
		Sum = 0
		for j in range(len(A3)):
			if Sum + A3[j] > 0:
				Sum += A3[j]
				my_max = max(my_max, j + 1)
			else:
				break
	return my_max
t = int(input())
for i in range(t):
	A = []
	n = int(input())
	for j in range(n):
		S = input()
		A.append(S)
	print(process(A))


def solve(mat, l, n):
	r = ord(l) - ord('a')
	mat.sort(key=lambda x: x[r] - (sum(x) - x[r]), reverse=True)
	ans = 0
	c = 0
	rest = 0
	for i in range(n):
		c += mat[i][r]
		rest += sum(mat[i]) - mat[i][r]
		if c > rest:
			ans = max(ans, i + 1)
	return ans
for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		l = input()
		a = 0
		b = 0
		c = 0
		d = 0
		e = 0
		for j in l:
			if j == 'a':
				a += 1
			elif j == 'b':
				b += 1
			elif j == 'c':
				c += 1
			elif j == 'd':
				d += 1
			else:
				e += 1
		mat.append([a, b, c, d, e])
	print(max(solve(mat, 'a', n), solve(mat, 'b', n), solve(mat, 'c', n), solve(mat, 'd', n), solve(mat, 'e', n)))


t = int(input())
for _ in range(t):
	n = int(input())
	lt = ['a', 'b', 'c', 'd', 'e']
	arr = [[], [], [], [], []]
	for i in range(n):
		st = input()
		for j in range(5):
			cnt = st.count(lt[j])
			arr[j].append(2 * cnt - len(st))
	for i in range(5):
		arr[i].sort(reverse=True)
	ans = -1
	cnt = [0, 0, 0, 0, 0]
	for i in range(n):
		for j in range(5):
			cnt[j] += arr[j][i]
			if cnt[j] > 0:
				ans = max(ans, i)
	print(ans + 1)


why_cant_you_take_inputs_while_printing_in_pycharm_it_is_so_annoying = [[input() for i in range(int(input()))] for _ in range(int(input()))]
for words in why_cant_you_take_inputs_while_printing_in_pycharm_it_is_so_annoying:
	maxes = []
	for letter in 'abcde':
		vals = sorted([2 * i.count(letter) - len(i) for i in words])[::-1]
		pi = ''
		storyL = 0
		storyB = 0
		for i in vals:
			if storyB + i > 0:
				storyB += i
				storyL += 1
		maxes.append(storyL)
	print(max(maxes))


t = int(input())

def gain(words, n):
	gains = [[], [], [], [], []]
	for word in words:
		freq = [0, 0, 0, 0, 0]
		length = len(word)
		for e in word:
			freq[ord(e) - ord('a')] += 1
		for i in range(5):
			gains[i].append(2 * freq[i] - length)
	for i in range(0, 5):
		gains[i].sort(reverse=True)
	return gains
output = []
for c in range(0, t):
	n = int(input())
	words = []
	for i in range(0, n):
		words.append(input())
	ans = 0
	gains = gain(words, n)
	for i in range(5):
		sum = 0
		for j in range(n):
			sum += gains[i][j]
			if sum <= 0:
				ans = max(j, ans)
				break
			else:
				ans = max(j + 1, ans)
	output.append(ans)
for e in output:
	print(e)


t = int(input())
for _ in range(t):
	n = int(input())
	(a, b, c, d, e) = ([], [], [], [], [])
	for i in range(n):
		word = input()
		wordLen = len(word)
		A = word.count('a')
		B = word.count('b')
		C = word.count('c')
		D = word.count('d')
		E = word.count('e')
		a.append(A - (wordLen - A))
		b.append(B - (wordLen - B))
		c.append(C - (wordLen - C))
		d.append(D - (wordLen - D))
		e.append(E - (wordLen - E))
	a.sort(reverse=True)
	b.sort(reverse=True)
	c.sort(reverse=True)
	d.sort(reverse=True)
	e.sort(reverse=True)
	(ca, cb, cc, cd, ce) = (0, 0, 0, 0, 0)
	for i in range(1, n + 1):
		ca += a[i - 1]
		cb += b[i - 1]
		cc += c[i - 1]
		cd += d[i - 1]
		ce += e[i - 1]
		if ca <= 0 and cb <= 0 and (cc <= 0) and (cd <= 0) and (ce <= 0):
			i -= 1
			break
	print(i)


for _ in range(int(input())):
	n = int(input())
	l = []
	lsct = ['a', 'b', 'c', 'd', 'e']
	tps = {i: [] for i in lsct}
	for i in range(n):
		tp = input()
		l.append(tp)
		dp = {i: 0 for i in lsct}
		for j in tp:
			if j in dp:
				dp[j] += 1
			else:
				dp[j] = 1
		for sd in lsct:
			tps[sd].append(dp[sd] - (len(tp) - dp[sd]))
	ans = 0
	for sd in lsct:
		tps[sd].sort(reverse=True)
		kp = 0
		lp = 0
		for j in tps[sd]:
			if kp + j > 0:
				kp += j
				lp += 1
		ans = max(ans, lp)
	print(ans)


import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
mod = 1000000007
sys.setrecursionlimit(1000000)
try:
	sys.stdin = open('actext.txt', 'r')
	OPENFILE = 1
except:
	pass

def get_ints():
	return map(int, input().split())

def palindrome(s):
	mid = len(s) // 2
	for i in range(mid):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def check(i, n):
	if 0 <= i < n:
		return True
	else:
		return False
t = int(input())
for tt in range(t):
	n = int(input())
	words = []
	for i in range(n):
		words.append(input())
	maxans = 0
	present_char = ('a', 'b', 'c', 'd', 'e')
	for ch in present_char:
		temp_arr = []
		for i in words:
			c = 0
			for j in i:
				if j == ch:
					c += 1
				else:
					c -= 1
			temp_arr.append(c)
		temp_arr.sort(reverse=True)
		ans = 0
		sm = 0
		for i in temp_arr:
			sm += i
			if sm <= 0:
				break
			ans += 1
		maxans = max(ans, maxans)
	print(maxans)


for i in range(int(input())):
	n = int(input())
	a = [[], [], [], [], []]
	k = 0
	for i in range(n):
		a[0].append(0)
		a[1].append(0)
		a[2].append(0)
		a[3].append(0)
		a[4].append(0)
		for j in input():
			a['abcde'.find(j)][i] += 1
		(a[0][i], a[1][i], a[2][i], a[3][i], a[4][i]) = (a[0][i] - a[1][i] - a[2][i] - a[3][i] - a[4][i], a[1][i] - a[0][i] - a[2][i] - a[3][i] - a[4][i], a[2][i] - a[1][i] - a[0][i] - a[3][i] - a[4][i], a[3][i] - a[1][i] - a[2][i] - a[0][i] - a[4][i], a[4][i] - a[1][i] - a[2][i] - a[3][i] - a[0][i])
	for i in range(5):
		a[i].sort()
		a[i] = a[i][::-1]
	for i in range(5):
		b = 0
		for j in range(n):
			b += a[i][j]
			if b <= 0:
				k = max(k, j)
				break
		else:
			k = n
			break
	print(k)


import sys, heapq
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(input())
	ans = 0
	for i in range(5):
		h = []
		t = 0
		for j in arr:
			a = 0
			for k in j:
				if ord(k) - ord('a') != i:
					a += 1
					t += 1
				else:
					t -= 1
					a -= 1
			heapq.heappush(h, -a)
		res = n
		while t >= 0 and h:
			res -= 1
			t += heapq.heappop(h)
		ans = max(ans, res)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = [[0, 0, 0, 0, 0] for i in range(n)]
	for i in range(n):
		ch = input()
		for j in ch:
			if j == 'a':
				l[i][0] += 1
			elif j == 'b':
				l[i][1] += 1
			elif j == 'c':
				l[i][2] += 1
			elif j == 'd':
				l[i][3] += 1
			elif j == 'e':
				l[i][4] += 1
	maxi = 0
	for i in range(5):
		t = []
		for j in l:
			t.append(j[i] - (j[i - 1] + j[i - 2] + j[i - 3] + j[i - 4]))
		t.sort(reverse=True)
		n = len(t)
		if t[0] <= 0:
			continue
		if maxi == 0:
			somme = t[0]
			maxi = 1
			i = 1
		else:
			somme = sum(t[:maxi])
			i = maxi
		while i < n:
			a = t[i]
			if somme + a > 0:
				somme += a
				maxi += 1
			else:
				break
			i += 1
	print(maxi)


for cycle in range(int(input())):
	words = []
	sums = []
	for i in range((n := int(input()))):
		word = input()
		words.append({j: 0 for j in 'abcde'})
		sums.append(0)
		for l in word:
			words[-1][l] += 1
			sums[-1] += 1
	remember = -1
	for ultrakrutoivascheletter in 'abcde':
		razn = sorted([words[i][ultrakrutoivascheletter] - (sums[i] - words[i][ultrakrutoivascheletter]) for i in range(n)], reverse=1)
		moesupervazhnoeznachenie = 0
		i = 0
		while i < n and moesupervazhnoeznachenie + razn[i] > 0:
			moesupervazhnoeznachenie += razn[i]
			i += 1
		remember = max(remember, i)
	print(remember)


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
from collections import deque, Counter, OrderedDict, defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inps():
	return input().strip()

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = []
	for i in range(n):
		l.append(insr())
	ans = 0
	for each in ['a', 'b', 'c', 'd', 'e']:
		s = []
		cnt = 0
		val = 0
		for every in l:
			g = Counter(every)
			if g[each] > len(every) - g[each]:
				cnt += 1
				val += 2 * g[each] - len(every)
			else:
				s.append(2 * g[each] - len(every))
		s.sort(reverse=True)
		for each in s:
			if val + each > 0:
				cnt += 1
				val += each
			else:
				break
		ans = max(ans, cnt)
	print(ans)


import sys

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def solve(n, arr):
	total = 0
	store = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
	a = []
	b = []
	c = []
	d = []
	e = []
	for ele in arr:
		total = len(ele)
		store = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
		for char in ele:
			store[char] += 1
		a.append(2 * store['a'] - total)
		b.append(2 * store['b'] - total)
		c.append(2 * store['c'] - total)
		d.append(2 * store['d'] - total)
		e.append(2 * store['e'] - total)
	a.sort()
	b.sort()
	c.sort()
	d.sort()
	e.sort()
	best = 0
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += a[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += b[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += c[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += d[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += e[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	sys.stdout.write(str(best) + '\n')
	return
T = get_int()
while T:
	n = get_int()
	tempN = n
	arr = []
	while tempN:
		s = get_string()
		arr.append(s)
		tempN -= 1
	solve(n, arr)
	T -= 1


def solve():
	n = int(input())
	l = []
	for i in range(n):
		s = input()
		l.append(s)
	p = ['a', 'b', 'c', 'd', 'e']
	m = 0
	for i in p:
		d = {}
		cp = []
		for ch in l:
			cp.append([ch.count(i), len(ch) - ch.count(i)])
		cp.sort()
		cp = cp[::-1]
		new = []
		for ii in range(len(cp)):
			diff = cp[ii][0] - cp[ii][1]
			new.append([diff, cp[ii][0], cp[ii][1]])
		new.sort(key=lambda x: (-x[0], x[1], -x[2]))
		cp = []
		for ii in range(len(new)):
			cp.append([new[ii][1], new[ii][2]])
		pref1 = [0] * (len(cp) + 1)
		pref2 = [0] * (len(cp) + 1)
		for ii in range(1, len(cp) + 1):
			(pair1, pair2) = cp[ii - 1]
			pref1[ii] = pref1[ii - 1] + pair1
			pref2[ii] = pref2[ii - 1] + pair2
			if pref1[ii] > pref2[ii]:
				m = max(m, ii)
	print(m)
for testis in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	(d1, d2, d3, d4, d5) = ([], [], [], [], [])
	for i in range(n):
		s = input()
		m = len(s)
		c = s.count('a')
		d1.append(2 * c - m)
		c = s.count('b')
		d2.append(2 * c - m)
		c = s.count('c')
		d3.append(2 * c - m)
		c = s.count('d')
		d4.append(2 * c - m)
		c = s.count('e')
		d5.append(2 * c - m)
	ans = 0
	d1.sort(reverse=True)
	d2.sort(reverse=True)
	d3.sort(reverse=True)
	d4.sort(reverse=True)
	d5.sort(reverse=True)
	(s, i, c) = (0, 0, 0)
	while i < len(d1) and d1[i] + s > 0:
		s += d1[i]
		c += 1
		i += 1
	ans = max(ans, c)
	(s, i, c) = (0, 0, 0)
	while i < len(d2) and d2[i] + s > 0:
		s += d2[i]
		c += 1
		i += 1
	ans = max(ans, c)
	(s, i, c) = (0, 0, 0)
	while i < len(d3) and d3[i] + s > 0:
		s += d3[i]
		c += 1
		i += 1
	ans = max(ans, c)
	(s, i, c) = (0, 0, 0)
	while i < len(d4) and d4[i] + s > 0:
		s += d4[i]
		c += 1
		i += 1
	ans = max(ans, c)
	(s, i, c) = (0, 0, 0)
	while i < len(d5) and d5[i] + s > 0:
		s += d5[i]
		c += 1
		i += 1
	ans = max(ans, c)
	print(ans)


from collections import defaultdict
T = int(input())
for _ in range(T):
	N = int(input())
	X = [None] * N
	count = [0] * N
	for i in range(N):
		tmp = [0] * 5
		for c in input():
			tmp[ord(c) - ord('a')] += 1
		s = sum(tmp)
		count[i] = s
		X[i] = [i * 2 - s for i in tmp]
	max_l = 0
	for target in range(5):
		x = [i[target] for i in X]
		x.sort(reverse=True)
		if x[0] <= 0:
			continue
		c = 1
		a = x[0]
		while a > 0 and c < N:
			a += x[c]
			c += 1
		max_l = max(max_l, c - (a <= 0))
	print(max_l)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	count = [[0] * 5 for __ in range(n)]
	for i in range(n):
		for x in input():
			count[i][ord(x) - 97] += 1
	ans = 0
	for x in range(5):
		a = sorted([count[i][x] - (sum(count[i]) - count[i][x]) for i in range(n)])
		cur = y = 0
		while a and y + a[-1] > 0:
			cur += 1
			y += a.pop()
		ans = max(ans, cur)
	print(ans)


from sys import *
import math
from collections import defaultdict, Counter
input = stdin.readline
I = int
R = range

def listInput():
	return list(map(int, input().strip().split()))

def lineInput():
	return map(int, input().strip().split())

def sJoin(a, sep):
	return '{}'.format(sep).join(a)

def arrJoin(a, sep):
	return '{}'.format(sep).join(map(str, a))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(math.sqrt(n) + 1), 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def main():
	alp = 'abcde'
	for k in R(I(input())):
		(n,) = lineInput()
		words = [input().strip() for i in R(n)]
		ans = 0
		for letter in alp:
			contribution = []
			for word in words:
				cnt = word.count(letter)
				c = 2 * cnt - len(word)
				contribution.append(c)
			contribution.sort(reverse=True)
			till = 0
			total = 0
			for i in contribution:
				total += i
				if total > 0:
					till += 1
				else:
					break
			ans = max(ans, till)
		print(ans)
main()


for _ in range(int(input())):
	tot = int(input())
	arr = []
	for x in range(tot):
		arr.append(input())
	mar = []
	ctar = []
	for x in arr:
		tpr = []
		tpr.append(x.count('a'))
		tpr.append(x.count('b'))
		tpr.append(x.count('c'))
		tpr.append(x.count('d'))
		tpr.append(x.count('e'))
		ctar.append(tpr)
	for x in range(5):
		tpr = []
		for y in ctar:
			a = 2 * y[x] - sum(y)
			tpr.append(a)
		tpr.sort(reverse=True)
		ct = 0
		sm = 0
		for y in tpr:
			sm += y
			ct += 1
			if sm <= 0:
				ct -= 1
				break
		mar.append(ct)
	print(max(mar))


import sys

def input():
	return sys.stdin.readline().strip()
T = int(input())
for _ in range(T):
	n = int(input())
	words = []
	for i in range(n):
		words.append(input())
	res = 0
	for c in ['a', 'b', 'c', 'd', 'e']:
		t = 0
		r = 0
		for w in sorted(words, key=lambda x: 2 * x.count(c) - len(x), reverse=True):
			r += 2 * w.count(c) - len(w)
			if r <= 0:
				break
			t += 1
		res = max(res, t)
	print(res)


from math import floor, gcd, sqrt, ceil
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def main():
	for _ in range(int(input())):
		n = int(input())
		w = [list(input()) for i in range(n)]
		m = []
		for i in range(5):
			c = chr(ord('a') + i)
			heap = []
			for i in range(n):
				heap.append([len(w[i]) - w[i].count(c) - w[i].count(c), w[i].count(c), len(w[i])])
			heapify(heap)
			(char, totchar) = (0, 0)
			ans = 0
			while heap:
				(x, y, z) = heappop(heap)
				char += y
				totchar += z - y
				if char <= totchar:
					break
				ans += 1
			m.append(ans)
		print(max(m))
main()


import collections
n_testcase = int(input())
for testcase in range(n_testcase):
	n = int(input())
	words = [input() for i in range(n)]
	words = [collections.Counter(word) for word in words]
	max_pick = 0
	for primary_letter in ['a', 'b', 'c', 'd', 'e']:
		diffs = []
		for word in words:
			diff = 0
			for (letter, count) in word.items():
				if letter == primary_letter:
					diff += count
				else:
					diff -= count
			diffs.append(diff)
		diffs.sort(reverse=True)
		diff_sum = 0
		i = 0
		while i < len(diffs) and diff_sum + diffs[i] > 0:
			diff_sum += diffs[i]
			i += 1
		max_pick = max(max_pick, i)
	print(max_pick)


import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import sys
import operator
from decimal import Decimal
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def li():
	return [int(i) for i in input().split()]

def lli(rows):
	return [li() for _ in range(rows)]

def si():
	return input()

def ii():
	return int(input())

def ins():
	return input().split()

def main():
	for _ in range(ii()):
		n = ii()
		d = defaultdict(list)
		c = [0] * 5
		all_count = [0] * 5
		for i in range(n):
			count = [0] * 5
			s = input()
			for si in s:
				q = ord(si) - ord('a')
				count[q] += 1
			sc = sum(count)
			for j in range(5):
				count[j] = 2 * count[j] - sc
				if count[j] >= 0:
					c[j] += 1
					all_count[j] += count[j]
				else:
					d[chr(j + ord('a'))].append(count[j])
		for i in range(5):
			p = chr(i + ord('a'))
			d[p].sort(reverse=True)
			k = 0
			l = len(d[p])
			while True:
				if l == 0:
					break
				all_count[i] += d[p][k]
				if all_count[i] > 0:
					c[i] += 1
				else:
					all_count[i] -= d[p][k]
					break
				k += 1
				if k == l:
					break
		m = 0
		for i in range(5):
			if all_count[i] > 0:
				m = max(m, c[i])
		print(m)
main()


def per(let):
	return 2 * let[i] - let[5]
for _ in range(int(input())):
	n = int(input())
	cook = []
	ans = [0]
	for _ in range(n):
		var = input()
		val = [var.count(_) for _ in ['a', 'b', 'c', 'd', 'e']]
		val.append(len(var))
		cook.append(val)
	for i in range(5):
		ssum = 0
		number = 0
		cook.sort(key=per, reverse=True)
		for j in range(len(cook)):
			ssum += per(cook[j])
			if ssum <= 0:
				break
			number += 1
		ans.append(number)
	print(max(ans))


t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for j in range(n):
		s = input()
		arr.append(s)
	alpha = ['a', 'b', 'c', 'd', 'e']
	a = []
	b = []
	c = []
	d = []
	e = []
	res = []
	for j in alpha:
		for k in arr:
			score = 0
			for l in k:
				if l == j:
					score += 1
				else:
					score -= 1
			if j == 'a':
				a.append(score)
			elif j == 'b':
				b.append(score)
			elif j == 'c':
				c.append(score)
			elif j == 'd':
				d.append(score)
			else:
				e.append(score)
		a = sorted(a, reverse=True)
		b = sorted(b, reverse=True)
		c = sorted(c, reverse=True)
		d = sorted(d, reverse=True)
		e = sorted(e, reverse=True)
	Sum = 0
	count = 0
	for j in range(0, len(a)):
		if Sum + a[j] == 0:
			break
		if Sum + a[j] >= 0:
			Sum += a[j]
			count += 1
		else:
			break
	res.append(count)
	Sum = 0
	count = 0
	for j in range(0, len(b)):
		if Sum + b[j] == 0:
			break
		if Sum + b[j] >= 0:
			Sum += b[j]
			count += 1
		else:
			break
	res.append(count)
	Sum = 0
	count = 0
	for j in range(0, len(c)):
		if Sum + c[j] == 0:
			break
		if Sum + c[j] >= 0:
			Sum += c[j]
			count += 1
		else:
			break
	res.append(count)
	Sum = 0
	count = 0
	for j in range(0, len(d)):
		if Sum + d[j] == 0:
			break
		if Sum + d[j] >= 0:
			Sum += d[j]
			count += 1
		else:
			break
	res.append(count)
	Sum = 0
	count = 0
	for j in range(0, len(e)):
		if Sum + e[j] == 0:
			break
		if Sum + e[j] >= 0:
			Sum += e[j]
			count += 1
		else:
			break
	res.append(count)
	print(max(res))


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
inf = float('inf')
mod = 10 ** 9 + 7

def get_list():
	return [int(i) for i in input().split()]

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
t = int(input())

def maxa(l, char):
	l.sort(key=lambda a: 2 * a.count(char) - len(a), reverse=True)
	this = 0
	that = 0
	maximum = 0
	for i in l:
		for j in i:
			if j == char:
				this += 1
			else:
				that += 1
		if this > that:
			maximum += 1
	return maximum
for i in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(input().strip())
	chars = list('abcde')
	ans = 0
	for i in chars:
		temp = maxa(l, i)
		ans = max(temp, ans)
	print(ans)


import sys

def input():
	return sys.stdin.readline().strip()
dic = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}
for _ in range(int(input())):
	ans = 0
	words = []
	for __ in range(int(input())):
		temp = [0] * 5
		for i in input():
			temp[dic[i]] += 1
		words.append(temp)
	for i in range(5):
		temp = 0
		n = 0
		switch = True
		for j in sorted(list(map(lambda x: sum(x) - 2 * x[i], words))):
			temp -= j
			n += 1
			if temp <= 0:
				switch = False
				break
		ans = max(ans, n - 1 + switch)
	print(ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	m = 0
	c = Counter(''.join(a))
	for max_char in ['a', 'b', 'c', 'd', 'e']:
		acounter = []
		for it in a:
			k = Counter(it)
			delta = k[max_char] - (len(it) - k[max_char])
			acounter.append(delta)
		acounter.sort(reverse=True)
		s = 0
		ans = 0
		for i in range(len(acounter)):
			s += acounter[i]
			if s > 0:
				ans += 1
			else:
				break
		if ans > m:
			m = ans
	print(m)


from sys import stdin
_input = stdin.readline
(_range, _max, _int, _str) = (range, max, int, str)

def solution():
	d = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}
	for _ in _range(_int(_input())):
		n = _int(_input())
		table = [[0] * n for i in _range(5)]
		for i in _range(n):
			c = 0
			for ch in _input().rstrip('\n'):
				table[d[ch]][i] += 1
				c += 1
			for j in _range(5):
				table[j][i] -= c - table[j][i]
		ans = [0] * 5
		for i in _range(5):
			table[i].sort(reverse=True)
			s = 0
			for j in _range(n):
				if s + table[i][j] > 0:
					ans[i] += 1
					s += table[i][j]
		print(_max(ans))
solution()


import math, bisect, heapq, random
for t in range(int(input())):
	n = int(input())
	a_c = []
	b_c = []
	c_c = []
	d_c = []
	e_c = []
	for i in range(n):
		(a, b, c, d, e) = (0, 0, 0, 0, 0)
		s = input()
		for i in s:
			if i == 'a':
				a += 1
			elif i == 'b':
				b += 1
			elif i == 'c':
				c += 1
			elif i == 'd':
				d += 1
			else:
				e += 1
		a_c.append(a - (b + c + d + e))
		b_c.append(b - (a + c + d + e))
		c_c.append(c - (b + a + d + e))
		d_c.append(d - (b + c + a + e))
		e_c.append(e - (b + c + d + a))
	arr = [a_c, b_c, c_c, d_c, e_c]
	ans = 0
	for a in arr:
		a.sort()
		a.reverse()
		s = 0
		ind = 0
		for i in a:
			s += i
			if s <= 0:
				break
			ind += 1
		ans = max(ans, ind)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	data = [[] for _ in range(n)]
	for i in range(n):
		s = input().rstrip()
		l = len(s)
		hi = [0] * 5
		for j in s:
			hi[ord(j) - 97] += 1
		for j in range(5):
			data[i].append(2 * hi[j] - l)
	result = 0
	for i in range(5):
		data.sort(key=lambda x: -x[i])
		cnt = 0
		ret = 0
		for j in data:
			if ret + j[i] <= 0:
				break
			ret += j[i]
			cnt += 1
		result = max(result, cnt)
	print(result)


for i in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(input())
	ans = 0
	for i in range(5):
		s = chr(ord('a') + i)
		b = []
		for j in range(len(l)):
			k = l[j].count(s)
			t = len(l[j]) - k
			b.append(k - t)
		b.sort(reverse=True)
		cur = 0
		for j in range(len(b)):
			cur += b[j]
			if cur > 0:
				ans = max(ans, j + 1)
			else:
				break
	print(ans)


def cum(fin):
	lst = fin[0]
	if lst > 0:
		res = 1
	else:
		res = 0
	for i in range(1, len(fin)):
		lst += fin[i]
		if lst <= 0:
			break
		res += 1
	return res
t = int(input())
for tims in range(t):
	n = int(input())
	c = []
	for i in range(n):
		c.append(input())
	mat = []
	for i in range(n):
		l = []
		l.append(c[i].count('a'))
		l.append(c[i].count('b'))
		l.append(c[i].count('c'))
		l.append(c[i].count('d'))
		l.append(c[i].count('e'))
		mat.append(l)
	fin = []
	for j in range(5):
		fini = []
		for i in range(n):
			sm = 0
			for k in range(5):
				sm += mat[i][k]
			p = 2 * mat[i][j] - sm
			fini.append(p)
		fin.append(fini)
	for a in fin:
		a.sort(reverse=True)
	res = []
	for i in range(5):
		res.append(cum(fin[i]))
	resi = max(res)
	print(resi)


T = int(input())
from collections import Counter
for _ in range(T):
	N = int(input())
	S = [input() for i in range(N)]
	ctrs = [Counter(s) for s in S]
	ans = 0
	for c in 'abcde':
		arr = [(2 * ctrs[i][c] - len(S[i]), i) for i in range(N)]
		arr.sort()
		z = a = tmp = 0
		while arr and (a + ctrs[arr[-1][1]][c]) * 2 > z + len(S[arr[-1][1]]):
			(_, i) = arr.pop()
			a += ctrs[i][c]
			z += len(S[i])
			tmp += 1
			ans = max(ans, tmp)
	print(ans)


t = int(input())
from collections import defaultdict
for _ in range(t):
	n = int(input())
	arr = []
	for x in range(n):
		val = input()
		arr.append(val)
	maxi = 0
	for var in ('a', 'b', 'c', 'd', 'e'):
		memo = {}
		for x in range(n):
			memo[arr[x]] = arr[x].count(var)
		arr = sorted(arr, key=lambda x: -(x.count(var) - (len(x) - memo[x])))
		ans = 0
		counta = 0
		rem = 0
		for i in range(0, len(arr)):
			counta += memo[arr[i]]
			rem += len(arr[i]) - memo[arr[i]]
			if counta - rem <= 0:
				break
			ans += 1
		maxi = max(maxi, ans)
	print(maxi)


from collections import defaultdict
t = int(input())
for i in range(t):
	d = {l: [0, 0, defaultdict(int)] for l in ['a', 'b', 'c', 'd', 'e']}
	n = int(input())
	for _ in range(n):
		this_word = {l: 0 for l in ['a', 'b', 'c', 'd', 'e']}
		s = input()
		for l in s:
			this_word[l] += 1
		for l in ['a', 'b', 'c', 'd', 'e']:
			if this_word[l] >= len(s) - this_word[l]:
				d[l][0] += 2 * this_word[l] - len(s)
				d[l][1] += 1
			else:
				d[l][2][len(s) - 2 * this_word[l]] += 1
	ans = {l: d[l][1] if d[l][0] > 0 else 0 for l in ['a', 'b', 'c', 'd', 'e']}
	for l in ['a', 'b', 'c', 'd', 'e']:
		val = d[l][0]
		j = 1
		if val > 0:
			while True:
				if j >= val:
					break
				if j in d[l][2]:
					if d[l][2][j] * j >= val:
						ans[l] += (val - 1) // j
						break
					else:
						ans[l] += d[l][2][j]
						val -= d[l][2][j] * j
				j += 1
	print(max(ans.values()))


for _ in range(int(input())):
	n = int(input())
	arr = [input() for _ in range(n)]
	mx = 0
	for c in ['a', 'b', 'c', 'd', 'e']:
		narr = []
		for w in arr:
			cd = cnd = 0
			for c2 in w:
				if c2 == c:
					cd += 1
				else:
					cnd += 1
			narr.append(cd - cnd)
		narr.sort(reverse=True)
		s = i = 0
		while i < len(narr) and s + narr[i] > 0:
			s += narr[i]
			i += 1
		mx = max(mx, i)
	print(mx)


from sys import stdin
input = stdin.readline

def solve(x, ind):
	x = [[x[i], i] for i in range(n)]
	(value, s) = (0, 0)
	for i in range(n):
		x[i][0] -= 2 * c[i][ind]
		value += c[i][ind]
		s += x[i][0] + c[i][ind]
	x.sort(key=lambda x: x[0], reverse=True)
	(ans, i) = (n, 0)
	while i < n and value <= s:
		value -= c[x[i][1]][ind]
		s -= x[i][0] + c[x[i][1]][ind]
		ans -= 1
		i += 1
	return ans

def answer():
	ans = solve(x[:], 0)
	ans = max(ans, solve(x[:], 1))
	ans = max(ans, solve(x[:], 2))
	ans = max(ans, solve(x[:], 3))
	ans = max(ans, solve(x[:], 4))
	return ans
for T in range(int(input())):
	n = int(input())
	c = [[0, 0, 0, 0, 0] for i in range(n)]
	x = []
	for i in range(n):
		for j in input().strip():
			c[i][ord(j) - 97] += 1
		x.append(sum(c[i]))
	print(answer())


import sys
input = sys.stdin.readline

def mp():
	return map(int, input().split())

def lmp():
	return list(map(int, input().split()))

def mps(A):
	return [tuple(map(int, input().split())) for _ in range(A)]
import math
import bisect
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque

def ceil(U, V):
	return (U + V - 1) // V

def modf1(N, MOD):
	return (N - 1) % MOD + 1
inf = int(1e+20)
mod = int(1000000000.0 + 7)
t = int(input())
for _ in range(t):
	n = int(input())
	word = []
	for i in range(n):
		s = input()[:-1]
		cnt = [0] * 5
		for j in s:
			cnt[ord(j) - ord('a')] += 1
		word.append(cnt)
	ans = 0
	for i in range(5):
		a = []
		for j in word:
			a.append(j[i] * 2 - sum(j))
		a.sort(reverse=True)
		ac = list(accumulate(a))
		cnt = 0
		for j in ac:
			if j > 0:
				cnt += 1
		ans = max(ans, cnt)
	print(ans)


import bisect
import math
import collections
import sys
import copy
from functools import reduce
import decimal
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

class Graphs:

	def __init__(self):
		self.graph = graphDict(list)

	def add_edge(self, u, v):
		self.graph[u].append(v)

	def dfs_utility(self, nodes, visited_nodes):
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes)
			else:
				return neighbour

	def dfs(self, node):
		Visited = set()
		self.dfs_utility(node, Visited)

	def bfs(self, node):
		visited = set()
		if node not in visited:
			queue.append(node)
			visited.add(node)
		while queue:
			parent = queue.popleft()
			print(parent)
			for item in self.graph[parent]:
				if item not in visited:
					queue.append(item)
					visited.add(item)

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	n = int(inp())
	dic = {'a': [], 'b': [], 'c': [], 'd': [], 'e': []}
	for i in range(n):
		s = inp()
		freq = collections.Counter(s)
		for item in dic:
			if item in freq:
				dic[item].append(freq[item] - (len(s) - freq[item]))
			else:
				dic[item].append(0 - len(s))
	for item in dic:
		dic[item].sort(reverse=True)
	ans = []
	for item in dic:
		total = 0
		i = 0
		while i < len(dic[item]) and total + dic[item][i] > 0:
			total += dic[item][i]
			i += 1
		ans.append(i)
	print(max(ans))


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf(sp=' '):
	return [int(i) for i in get().split(sp)]

def put(a, end='\n'):
	stdout.write(str(a) + end)

def putf(a, sep=' ', end='\n'):
	stdout.write(sep.join([str(i) for i in a]) + end)

def solve(n, a, c):
	a.sort(key=lambda x: -(2 * x[c] - x[5]))
	ans = 0
	cur_c = 0
	cur_l = 0
	for i in range(n):
		cur_c += a[i][c]
		cur_l += a[i][5]
		if cur_c > cur_l - cur_c:
			ans += 1
		else:
			cur_c -= a[i][c]
			cur_l -= a[i][5]
	return ans

def main():
	for _ in range(int(get())):
		n = int(get())
		a = [[0, 0, 0, 0, 0, 0] for i in range(n)]
		for i in range(n):
			w = get()
			for j in w:
				a[i][ord(j) - 97] += 1
				a[i][5] += 1
		ans = 0
		for c in range(5):
			ans = max(ans, solve(n, a, c))
		put(ans)
main()


t = int(input())

def maxi(n, L):
	leng = [len(s) for s in L]
	count = [5 * [0] for i in range(n)]
	for i in range(n):
		x = L[i]
		for c in x:
			count[i][ord(c) - ord('a')] += 1
	res = 5 * [0]
	for i in range(5):
		toti = [2 * x[i] - sum(x) for x in count]
		toti = sorted(toti, key=lambda a: -a)
		a = len(toti)
		s = toti[0]
		j = 1
		if a == 1:
			if s > 0:
				res[i] = 1
			else:
				res[i] = 0
		else:
			while j < a and s > 0:
				s += toti[j]
				j += 1
			if j == a:
				if s > 0:
					res[i] = j
				else:
					res[i] = j - 1
			else:
				res[i] = j - 1
	return max(res)
for _ in range(t):
	n = int(input())
	L = []
	for _ in range(n):
		L.append(input())
	print(maxi(n, L))


def naiveSolve():
	return
from collections import Counter
chars = 'abcde'

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		n = int(input())
		words = []
		for __ in range(n):
			cnt = Counter(input())
			words.append((cnt['a'], cnt['b'], cnt['c'], cnt['d'], cnt['e']))
		ans = 0
		for i in range(5):
			words2 = []
			for word in words:
				maj = 0
				minor = 0
				for j in range(5):
					if i == j:
						maj += word[j]
					else:
						minor += word[j]
				words2.append((maj, minor))
			words2.sort(key=lambda x: x[0] - x[1], reverse=True)
			wordCnts = 0
			majority = 0
			minority = 0
			for j in range(n):
				majority += words2[j][0]
				minority += words2[j][1]
				if majority > minority:
					wordCnts += 1
				else:
					break
			ans = max(ans, wordCnts)
		allans.append(ans)
	multiLineArrayPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(l, r):
	print('? {} {}'.format(l, r))
	sys.stdout.flush()
	return int(input())

def answerInteractive(x):
	print('! {}'.format(x))
	sys.stdout.flush()
inf = float('inf')
MOD = 998244353
from math import gcd, floor, ceil
for _abc in range(1):
	main()


for _ in range(int(input())):
	n = int(input())
	a = [input() for i in range(n)]
	res = 0
	for i in 'abcde':
		temp = []
		tot = 0
		cnt = 0
		for s in a:
			temp.append(2 * s.count(i) - len(s))
		temp.sort(reverse=True)
		for k in temp:
			tot += k
			if tot <= 0:
				break
			cnt += 1
		res = max(res, cnt)
	print(res)


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations
import sys, io, os
inf = float('inf')
mod = 10 ** 9 + 7

def get_list():
	return [int(i) for i in input().split()]

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())

def maxa(l, char):
	l.sort(key=lambda a: 2 * a.count(char) - len(a), reverse=True)
	this = 0
	that = 0
	maximum = 0
	for i in l:
		for j in i:
			if j == char:
				this += 1
			else:
				that += 1
		if this > that:
			maximum += 1
	return maximum
for i in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(input().strip())
	chars = list('abcde')
	ans = 0
	for i in chars:
		temp = maxa(l, i)
		ans = max(temp, ans)
	print(ans)


import sys
import math
import heapq
from collections import defaultdict
from collections import OrderedDict as od
from collections import deque
from itertools import permutations as pp
from itertools import combinations as cc
from sys import stdin
from functools import cmp_to_key
from functools import lru_cache
from bisect import bisect_left as bs_l
from bisect import bisect_right as bs_r
input = sys.stdin.readline
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 5)

def helper(s):
	pass
T = int(input())
for _ in range(T):
	n = int(input())
	l = list()
	for i in range(n):
		s = input().strip()
		d1 = defaultdict(int)
		for j in s:
			d1[j] += 1
		l.append([d1['a'], d1['b'], d1['c'], d1['d'], d1['e'], s])
	ans = 0
	l.sort(key=lambda x: x[0] - x[1] - x[2] - x[3] - x[4], reverse=True)
	(aa, rem) = (0, 0)
	c = 0
	sc = 0
	for i in l:
		if aa + i[0] > rem + i[1] + i[2] + i[3] + i[4]:
			c += 1
			aa += i[0]
			rem += i[1] + i[2] + i[3] + i[4]
			if sc:
				c += sc
				sc = 0
	ans = max(ans, c)
	l.sort(key=lambda x: x[1] - x[0] - x[2] - x[3] - x[4], reverse=True)
	(bb, rem) = (0, 0)
	c = 0
	sc = 0
	for i in l:
		if bb + i[1] > rem + i[0] + i[2] + i[3] + i[4]:
			c += 1
			bb += i[1]
			rem += i[0] + i[2] + i[3] + i[4]
		else:
			break
	ans = max(ans, c)
	l.sort(key=lambda x: x[2] - x[0] - x[1] - x[3] - x[4], reverse=True)
	(cc, rem) = (0, 0)
	c = 0
	sc = 0
	for i in l:
		if cc + i[2] > rem + i[0] + i[1] + i[3] + i[4]:
			c += 1
			cc += i[2]
			rem += i[0] + i[1] + i[3] + i[4]
		else:
			break
	ans = max(ans, c)
	l.sort(key=lambda x: x[3] - x[0] - x[1] - x[2] - x[4], reverse=True)
	(dd, rem) = (0, 0)
	c = 0
	sc = 0
	for i in l:
		if dd + i[3] > rem + i[0] + i[1] + i[2] + i[4]:
			c += 1
			dd += i[3]
			rem += i[0] + i[1] + i[2] + i[4]
		else:
			break
	ans = max(ans, c)
	l.sort(key=lambda x: x[4] - x[0] - x[1] - x[2] - x[3], reverse=True)
	(ee, rem) = (0, 0)
	c = 0
	sc = 0
	for i in l:
		if ee + i[4] > rem + i[0] + i[1] + i[2] + i[3]:
			c += 1
			ee += i[4]
			rem += i[0] + i[1] + i[2] + i[3]
		else:
			break
	ans = max(ans, c)
	print(ans)


import sys
input = sys.stdin.readline
from collections import Counter as cc
I = lambda : list(map(int, input().split()))

def ans(arr):
	arr.sort(reverse=True, key=lambda x: [x[0] > x[1], x[0] - x[1], x[0]])
	(x, y) = arr[0]
	if x <= y:
		an = 0
		x = y = 0
	else:
		an = 1
	for i in range(1, len(arr)):
		(p, q) = arr[i]
		if x + p > y + q:
			an += 1
			x += p
			y += q
	return an
(t,) = I()
for _ in range(t):
	(n,) = I()
	a = []
	b = []
	c = []
	d = []
	e = []
	for i in range(n):
		x = input().strip()
		temp = [0] * 5
		le = len(x)
		for j in x:
			temp[ord(j) - 97] += 1
		a.append([temp[0], le - temp[0]])
		b.append([temp[1], le - temp[1]])
		c.append([temp[2], le - temp[2]])
		d.append([temp[3], le - temp[3]])
		e.append([temp[4], le - temp[4]])
	print(max(map(ans, [a, b, c, d, e])))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main(t):
	n = int(input())
	diff = [[] for i in range(5)]
	for i in range(n):
		fre = [0] * 5
		word = input()[:-2]
		for c in word:
			fre[c - 97] += 1
		for j in range(5):
			diff[j].append(fre[j] - (len(word) - fre[j]))
	ans = 0
	for j in range(5):
		diff[j] = sorted(diff[j], reverse=True)
		accu = 0
		temp = 0
		for subdiff in diff[j]:
			accu += subdiff
			if accu > 0:
				temp += 1
			else:
				break
		ans = max(ans, temp)
	print(ans)
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
from collections import Counter
for _ in range(rn()):
	n = rn()
	words = [rs() for i in range(n)]
	ans = 0
	d = [Counter(word) for word in words]
	for char in ['a', 'b', 'c', 'd', 'e']:
		poss = 0
		diffs = []
		for i in range(n):
			diff = len(words[i]) - 2 * d[i][char]
			diffs.append(diff)
		diffs.sort()
		acc = 0
		for i in range(n):
			if acc + diffs[i] >= 0:
				break
			acc += diffs[i]
			poss += 1
		ans = max(ans, poss)
	print(ans)


from itertools import product, combinations
from math import sqrt
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [[0, 0, 0, 0, 0] for i in range(n)]
	lengths = [0 for i in range(n)]
	for i in range(n):
		s = input()
		for el in s:
			arr[i][ord(el) - ord('a')] += 1
		lengths[i] = len(s)
	a = []
	b = []
	c = []
	d = []
	e = []
	for i in range(n):
		a.append(2 * arr[i][0] - lengths[i])
		b.append(2 * arr[i][1] - lengths[i])
		c.append(2 * arr[i][2] - lengths[i])
		d.append(2 * arr[i][3] - lengths[i])
		e.append(2 * arr[i][4] - lengths[i])
	a.sort()
	b.sort()
	c.sort()
	d.sort()
	e.sort()
	if a[-1] <= 0 and b[-1] <= 0 and (c[-1] <= 0) and (d[-1] <= 0) and (e[-1] <= 0):
		ans = 0
	else:
		ans = 1
		for array in [a, b, c, d, e]:
			if array[-1] <= 0:
				continue
			index = n - 1
			summ = array[n - 1]
			while summ > 0:
				if index < 0:
					break
				index -= 1
				summ += array[index]
				if index == 0 and summ > 0:
					ans = n
					break
			if summ <= 0:
				ans = max(ans, n - 1 - index)
	print(ans)


from sys import stdin

def func(x, t):

	def sortt(aa):
		oo = 0
		xx = 0
		for p in range(5):
			if p == x:
				xx += aa[p]
			else:
				oo += aa[p]
		return xx - oo
	arr.sort(key=sortt)
	el = tc[x]
	o = t - tc[x]
	c = n
	for i in arr:
		if el > o:
			return c
		else:
			c -= 1
		for j in range(5):
			if j == x:
				el -= i[j]
			else:
				o -= i[j]
	return 0
for _ in range(int(stdin.readline())):
	n = int(input())
	arr = []
	d = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}
	tc = [0 for i in range(5)]
	t = 0
	for i in range(n):
		s = input()
		t += len(s)
		ar = [0 for i in range(5)]
		for j in s:
			ar[d[j]] += 1
		for i in range(5):
			tc[i] += ar[i]
		arr.append(ar)
	ans = 0
	for ii in range(5):
		ans = max(ans, func(ii, t))
	print(ans)


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations, accumulate, zip_longest, combinations_with_replacement
from math import gcd, floor, inf, log2, sqrt, log10, factorial
from bisect import bisect_right, bisect_left
from statistics import mode
from string import ascii_lowercase, ascii_uppercase

def sum_val(dic):
	return sum((val for (key, val) in dic.items()))

def solve(dict, char):
	arr = []
	for (i, d) in dict.items():
		val = sum_val(d)
		if char in d:
			arr.append(d[char] - val + d[char])
		else:
			arr.append(-val)
	rev = sorted(arr, reverse=True)
	presum = list(accumulate(rev))
	return sum((1 for i in presum if i > 0))
cases = int(input())
for _ in range(cases):
	num = int(input())
	freq = {}
	for i in range(num):
		s = input()
		freq[i] = Counter(s)
	ans = []
	word = 'abcde'
	for char in word:
		ans.append(solve(freq, char))
	print(max(ans))


from collections import defaultdict

def solve(data):
	letters = ['a', 'b', 'c', 'd', 'e']
	_dict = {}
	for word in data:
		_dict[word] = defaultdict(int)
		_dict[word]['len'] = len(word)
		for letter in word:
			_dict[word][letter] += 1
	max_need = 0
	for letter in letters:
		data = sorted(data, key=lambda word: 2 * _dict[word][letter] - _dict[word]['len'], reverse=True)
		letter_count = _dict[data[0]][letter]
		all_count = len(data[0])
		word_ptr = 1
		while 2 * letter_count > all_count and word_ptr < len(data):
			letter_count += _dict[data[word_ptr]][letter]
			all_count += len(data[word_ptr])
			word_ptr += 1
		if 2 * letter_count <= all_count:
			word_ptr -= 1
		max_need = max(max_need, word_ptr)
	return max_need

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		words = [input() for i in range(n)]
		answer = solve(words)
		print(answer)
main()


l = []

def fun(x):
	temp = []
	for i in range(len(l)):
		cur = 0
		for k in l[i]:
			if k == x:
				cur += 1
			else:
				cur -= 1
		temp.append(cur)
	temp.sort(reverse=True)
	now = 0
	s = 0
	for t in temp:
		s += t
		if s <= 0:
			break
		now += 1
	return now
for _ in range(int(input())):
	n = int(input())
	l = []
	for _ in range(n):
		l.append(input())
	print(max(fun('a'), fun('b'), fun('c'), fun('d'), fun('e')))


for _ in range(int(input())):
	n = int(input())
	globans = -1
	f = [[0] * 5 for i in range(n)]
	for i in range(n):
		cnt = [0] * 5
		w = input()
		for el in w:
			cnt[ord(el) - 97] += 1
		tot = len(w)
		for x in range(5):
			res = cnt[x] - (tot - cnt[x])
			f[i][x] = res
	for pot in range(5):
		tmp = list()
		for i in range(n):
			tmp.append(f[i][pot])
		tmp = sorted(tmp, key=lambda x: -x)
		rol = 0
		idx = 0
		count = 0
		while idx < n:
			rol += tmp[idx]
			if rol <= 0:
				break
			idx += 1
			count += 1
		globans = max(count, globans)
	print(globans)


for _ in range(int(input())):
	n = int(input())
	w = []
	for i in range(n):
		s = input()
		w.append(s)
	ans = 0
	for c in 'abcde':
		wc = [word.count(c) * 2 - len(word) for word in w]
		wc.sort(reverse=True)
		p = 0
		res = 0
		for e in wc:
			p += e
			if p > 0:
				res += 1
			else:
				break
		if res > ans:
			ans = res
	print(ans)


for _ in range(int(input())):
	(word_a, word_b, word_c, word_d, word_e) = ([], [], [], [], [])
	for _ in range(int(input())):
		word = input()
		(a, b, c, d, e) = (0, 0, 0, 0, 0)
		for w in word:
			if w == 'a':
				a += 1
			elif w == 'b':
				b += 1
			elif w == 'c':
				c += 1
			elif w == 'd':
				d += 1
			else:
				e += 1
		word_a.append(a - (len(word) - a))
		word_b.append(b - (len(word) - b))
		word_c.append(c - (len(word) - c))
		word_d.append(d - (len(word) - d))
		word_e.append(e - (len(word) - e))
	(word_a, word_b, word_c, word_d, word_e) = (sorted(word_a), sorted(word_b), sorted(word_c), sorted(word_d), sorted(word_e))
	n_words = 0
	word_t = [word_a, word_b, word_c, word_d, word_e]
	for f in range(5):
		t = 0
		for x in range(len(word_a) - 1, -1, -1):
			if word_t[f][x] + t > 0:
				t += word_t[f][x]
			else:
				t += word_t[f][x]
				n_words = max(n_words, len(word_a) - x - 1)
				break
		if t > 0:
			n_words = max(n_words, len(word_a) - x)
	print(n_words)


ttt = int(input())
while ttt > 0:
	ttt -= 1
	n = int(input())
	n_word = [[0] * 5 for _ in range(n)]
	for i_ in range(0, n):
		i_word = input()
		for j in i_word:
			if j == 'a':
				n_word[i_][0] += 1
			if j == 'b':
				n_word[i_][1] += 1
			if j == 'c':
				n_word[i_][2] += 1
			if j == 'd':
				n_word[i_][3] += 1
			if j == 'e':
				n_word[i_][4] += 1
	sum = [0, 0, 0, 0, 0]
	for mm in range(5):
		nnn = [0] * n
		for i in range(n):
			nnn[i] = 2 * n_word[i][mm] - (n_word[i][1] + n_word[i][2] + n_word[i][3] + n_word[i][4] + n_word[i][0])
		nnn.sort(reverse=True)
		if nnn[0] < 1:
			sum[mm] = 0
		else:
			sum[mm] = 0
			sum_nnn = 0
			for num in nnn:
				sum_nnn += num
				if sum_nnn > 0:
					sum[mm] += 1
				else:
					break
	ans = max(sum)
	if ans < 1:
		print(0)
	else:
		print(ans)


T = int(input())
for case in range(T):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(input())
	ans = 0
	flag = True
	for i in range(5):
		ele = []
		cyes = 0
		cno = 0
		for s in arr:
			yes = s.count(chr(i + ord('a')))
			no = len(s) - yes
			ele.append((yes, no))
			cyes += yes
			cno += no
		ele.sort(key=lambda x: [x[1] - x[0]])
		if cyes > cno:
			print(n)
			flag = False
			break
		for i in range(len(ele) - 1, -1, -1):
			cyes -= ele[i][0]
			cno -= ele[i][1]
			if cyes > cno:
				ans = max(ans, i)
	if flag:
		print(ans)


def f(string, c):
	return 2 * string.count(c) - len(string)

def func(x):
	a = sum(x)
	ans = len(x)
	while a <= 0:
		try:
			a -= x.pop(-1)
			ans -= 1
		except:
			break
	return ans
for _ in range(int(input())):
	lis = [[], [], [], [], []]
	for _ in range(int(input())):
		x = input()
		a = ['a', 'b', 'c', 'd', 'e']
		for i in range(5):
			lis[i].append(f(x, a[i]))
	for i in range(len(lis)):
		lis[i].sort(reverse=True)
	(a, b, c, d, e) = map(func, lis)
	print(max(a, b, c, d, e))


def advantage(c, w):
	occ = w.count(c)
	return -(occ - (len(w) - occ))
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	words = []
	for _ in range(n):
		words.append(input())
	opt = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
	for c in ['a', 'b', 'c', 'd', 'e']:
		swords = sorted(words, key=lambda w: advantage(c, w))
		tot_advantage = 0
		if -advantage(c, swords[0]) > 0:
			i = 0
			while i < len(swords) and tot_advantage - advantage(c, swords[i]) > 0:
				tot_advantage += -advantage(c, swords[i])
				i += 1
			opt[c] = i
		else:
			opt[c] = 0
	print(str(max([opt[c] for c in ['a', 'b', 'c', 'd', 'e']])))


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		s = list(input())
		a.append(s)
	ans = -999999999
	for i in range(5):
		ch = chr(97 + i)
		b = []
		for i in range(n):
			t = 0
			t1 = 0
			for j in range(len(a[i])):
				if a[i][j] == ch:
					t += 1
				else:
					t1 += 1
			b.append([t - t1, t, t1, i])
		b.sort(reverse=True)
		c = []
		t = 0
		t1 = 0
		for i in range(len(b)):
			t += b[i][1]
			t1 += b[i][2]
			if t <= t1:
				break
			c.append(b[i][3])
		if len(c) >= ans:
			ans = len(c)
	if ans == -999999999:
		ans = 0
	print(ans)


t = int(input())

def key1(a):
	return a[ind] * 2 - sum(a)
for qwe in range(t):
	n = int(input())
	l = [0] * n
	for i in range(n):
		s = input()
		tl = [0] * 5
		for j in s:
			if j == 'a':
				tl[0] += 1
			elif j == 'b':
				tl[1] += 1
			elif j == 'c':
				tl[2] += 1
			elif j == 'd':
				tl[3] += 1
			elif j == 'e':
				tl[4] += 1
		tl = tuple(tl)
		l[i] = tl
	ans = [0] * 5
	for ind in range(5):
		b = [0] * 5
		l.sort(key=key1, reverse=True)
		tempans = 0
		for i in range(n):
			for j in range(5):
				b[j] += l[i][j]
			if 2 * b[ind] <= sum(b):
				for j in range(5):
					b[j] -= l[i][j]
			else:
				tempans += 1
		ans[ind] = tempans
	print(max(ans))


import time
from queue import Queue
from itertools import accumulate, count
from io import BytesIO, IOBase
from itertools import combinations
import threading
from collections import deque
from functools import reduce, cmp_to_key
import sys
from math import sqrt
import heapq
import random
import math
from collections import defaultdict
from collections import Counter
import io
import os
import bisect
from fractions import Fraction

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def swap(arr, a, b):
	(arr[a], arr[b]) = (arr[b], arr[a])

def cal(words, letter):
	newArr = []
	for word in words:
		effective = 2 * word.count(letter) - len(word)
		newArr.append(effective)
	newArr.sort(reverse=True)
	s = 0
	ans = 0
	for i in newArr:
		s += i
		if s <= 0:
			break
		ans += 1
	return ans
for _ in range(iinput()):
	n = iinput()
	words = []
	for i in range(n):
		words.append(input())
	ans = 0
	for i in ['a', 'b', 'c', 'd', 'e']:
		ans = max(ans, cal(words, i))
	print(ans)


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def myceil(x, y):
	return (x + y - 1) // y

def Solution(arr, n):
	freq = []
	ans = 0
	for s in arr:
		hm = [0, 0, 0, 0, 0]
		for c in s:
			hm[ord(c) - 97] += 1
		freq.append(hm)
	for i in range(5):
		queue = []
		for j in range(n):
			itm = freq[j]
			sm = sum(itm)
			heapq.heappush(queue, -1 * (itm[i] - (sm - itm[i])))
		sm = 0
		tmpAns = 0
		while len(queue):
			v = -1 * heapq.heappop(queue)
			if sm + v > 0:
				tmpAns += 1
				sm += v
			else:
				break
		ans = max(ans, tmpAns)
	print(ans)

def main():
	for _ in range(get_int()):
		n = get_int()
		arr = [get_string() for _ in range(n)]
		Solution(arr, n)
main()


import collections

def main():
	t = int(input().strip())
	while t > 0:
		t -= 1
		n = int(input().strip())
		words = [input().strip() for i in range(n)]
		best = 0
		for letter in 'abcde':
			counts = [(s.count(letter), len(s)) for s in words]
			counts.sort(key=lambda tup: tup[0] + tup[0] - tup[1], reverse=True)
			this = 0
			other = 0
			lbest = 0
			for (num, length) in counts:
				den = length - num
				this += num
				other += den
				if this <= other:
					break
				lbest += 1
			best = max(best, lbest)
		print(best)
main()


from collections import Counter, deque, defaultdict
from heapq import *

def inp():
	return int(input())

def mapInput():
	return map(int, input().split())

def arrInput():
	return list(map(int, input().split()))

def task():
	n = inp()
	words = []
	for _ in range(n):
		words.append(input())
	totalLen = 0
	wList = [list() for _ in range(5)]
	for (i, w) in enumerate(words):
		totalLen += len(w)
		lCount = defaultdict(int)
		for char in w:
			char = ord(char) - 97
			lCount[char] += 1
		for j in range(5):
			wList[j].append(2 * lCount[j] - len(w))
	for j in range(5):
		wList[j].sort(reverse=True)
	mx = 0
	for j in range(5):
		s = wList[j][0]
		i = 1
		while s > 0 and i < len(wList[j]):
			s += wList[j][i]
			i += 1
		if s > 0:
			mx = max(mx, i)
		elif s - wList[j][i - 1] > 0:
			mx = max(mx, i - 1)
	print(mx)
for _ in range(inp()):
	task()


t = int(input())
for _ in range(t):
	ovr = [0 for _ in range(5)]
	ans = 0
	n = int(input())
	d = [[0 for _ in range(5)] for __ in range(n)]
	for i in range(n):
		a = [0 for _ in range(5)]
		s = input()
		for c in s:
			ind = ord(c) - ord('a')
			a[ind] += 1
			ovr[ind] += 1
		for j in range(5):
			d[i][j] = sum(a) - 2 * a[j]
	for i in range(5):
		d = sorted(d, key=lambda x: x[i], reverse=True)
		diff = ovr[i] - (sum(ovr) - ovr[i])
		cnt = 0
		for ar in d:
			if diff > 0:
				ans = max(ans, n - cnt)
			diff += ar[i]
			cnt += 1
	print(ans)


def solve(n, arr):
	sorted_arr = [[0 for _ in range(5)] for _ in range(n)]
	for x in range(n):
		length = len(arr[x])
		for i in range(5):
			sorted_arr[x][i] = 2 * arr[x].count(chr(97 + i)) - length
	best = 0
	for x in range(5):
		sorted_arr = sorted(sorted_arr, key=lambda i: i[x], reverse=True)
		curr = 0
		check = False
		for i in range(n):
			curr += sorted_arr[i][x]
			if curr < 1:
				best = max(best, i)
				check = True
				break
		if not check:
			print(n)
			return
	print(best)
for _ in range(int(input())):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(input())
	solve(n, arr)


T = int(input())
for tc in range(T):
	n = int(input())
	words = []
	for i in range(n):
		word = input()
		words.append(word)
	chars = ['a', 'b', 'c', 'd', 'e']
	ans = 0
	for ch in chars:
		words.sort(key=lambda word: 2 * word.count(ch) - len(word), reverse=True)
		net_rem_freq = 0
		net_char_freq = 0
		total_words = 0
		for word in words:
			net_char_freq += word.count(ch)
			net_rem_freq += len(word) - word.count(ch)
			if net_char_freq <= net_rem_freq:
				break
			total_words += 1
		ans = max(ans, total_words)
	print(ans)


MULTIPLE_CASE = True

def get_res(data, index) -> int:
	a = []
	for i in data:
		temp = 0
		for j in i:
			temp -= j
		temp += i[index] * 2
		a.append(temp)
	a.sort(reverse=True)
	if a[0] <= 0:
		return 0
	count = 0
	sum = 0
	for i in a:
		if sum + i > 0:
			sum += i
			count += 1
		else:
			return count
	return count

def solve():
	n = int(input())
	data = []
	for i in range(n):
		s = str(input())
		a = [0] * 5
		for j in s:
			a[ord(j) - ord('a')] += 1
		data.append(a)
	res = 0
	for i in range(5):
		res = max(res, get_res(data, i))
	print(res)
T = 1
if MULTIPLE_CASE:
	T = int(input())
while T > 0:
	T -= 1
	solve()


for _ in range(int(input())):
	s = []
	n = int(input())
	for _ in range(n):
		s.append(input())
	t = [[0] * 5 for _ in range(n)]
	for i in range(n):
		z = [0] * 26
		for j in range(len(s[i])):
			z[ord(s[i][j]) - 97] += 1
		for k in range(5):
			t[i][k] = 2 * z[k] - len(s[i])
	ans = 0
	for k in range(5):
		ba = []
		vtx = ant = 0
		for i in range(n):
			ba.append(t[i][k])
		ba.sort(reverse=True)
		for i in range(n):
			vtx += ba[i]
			if vtx <= 0:
				break
			ant += 1
		ans = max(ant, ans)
	print(ans)


from collections import Counter

def f(a):
	l = 0
	ans = 0
	t = []
	tc = [0, 0, 0, 0, 0]
	for i in a:
		cnt = Counter(i)
		tr = [0, 0, 0, 0, 0]
		for ltr in cnt:
			tr[ord(ltr) - ord('a')] += cnt[ltr]
			tc[ord(ltr) - ord('a')] += cnt[ltr]
		t.append(tr)
	total = sum(tc)
	for chr in range(0, 5):
		temp = total - tc[chr]
		tempchr = tc[chr]
		tans = len(a)
		t = sorted(t, key=lambda s: s[chr] - (sum(s) - s[chr]))
		for lst in t:
			if tempchr > temp:
				ans = max(ans, tans)
				break
			else:
				tempchr -= lst[chr]
				temp = temp - sum(lst) + lst[chr]
				tans -= 1
	return ans
	ans = 0
for _ in range(int(input())):
	n = int(input())
	q = []
	for i in range(n):
		q.append(input())
	print(f(q))


for _ in range(int(input())):
	n = int(input())
	sete = [input() for _ in range(n)]
	cl = []
	for i in range(n):
		cl.append({'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'len': 0})
		for j in sete[i]:
			cl[i][j] += 1
			cl[i]['len'] += 1
	maxb = 0
	for b in ['a', 'b', 'c', 'd', 'e']:
		pref = 0
		xk = 0
		qw = 0
		for i in sorted(cl, key=lambda x: x[b] + x[b] - x['len'], reverse=True):
			if xk + i[b] > pref + i['len'] - i[b]:
				xk += i[b]
				pref += i['len'] - i[b]
				qw += 1
			else:
				break
		maxb = max(maxb, qw)
	print(maxb)


for _ in range(int(input())):
	n = int(input())
	mai = []
	for i in range(n):
		mai.append(input())
	word = 'abcde'
	ans = 0
	for i in word:
		confirm = 0
		pos = 0
		neg = []
		flag = False
		for j in mai:
			xx = j.count(i)
			le = len(j) - xx
			if xx > le:
				flag = True
			if xx >= le:
				confirm += 1
				pos += xx - le
			else:
				neg.append(le - xx)
		neg.sort()
		for i in neg:
			if pos >= i:
				pos -= i
				confirm += 1
			else:
				break
		if pos == 0:
			if flag:
				ans = max(ans, confirm - 1)
		else:
			ans = max(ans, confirm)
	print(ans)


import io
import os
import collections
import math
import functools
import itertools
import bisect
import heapq
from sys import stdin, stdout, stderr
from collections import *
from math import *
from functools import *
from itertools import *
from heapq import *
from bisect import bisect_left, bisect_right, insort_left, insort_right
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_ints():
	return list(map(int, input().split()))

def get_int():
	return int(input())

def get_str():
	return ''.join(list(map(chr, input()))[:-1])

def eprint(*args):
	stderr.write(', '.join(map(str, args)) + '\n')

def print(*args):
	stdout.write(' '.join(map(str, args)) + '\n')
t = get_int()
for tt in range(t):
	n = get_int()
	words = []
	for i in range(n):
		w = get_str()
		word = (w.count('a'), w.count('b'), w.count('c'), w.count('d'), w.count('e'))
		words.append(word)
	best = 0
	for mc in range(5):
		words.sort(key=lambda word: -(2 * word[mc] - sum(word)))
		mcc = 0
		rest = 0
		for (i, word) in enumerate(words, 1):
			rest += sum(word) - word[mc]
			mcc += word[mc]
			if mcc > rest:
				best = max(best, i)
	print(best)


from collections import *

def f(s, c):
	cnt = Counter(s)
	return cnt[c] - sum(map(lambda x: x[1], list(filter(lambda x: x[0] != c, cnt.items()))))
t = int(input())
for _ in range(t):
	n = int(input())
	arr = defaultdict(lambda : [None for _ in range(5)])
	for j in range(n):
		s = input().strip()
		for (i, c) in enumerate('abcde'):
			arr[j][i] = f(s, c)
	ans = 0
	for (i, c) in enumerate('abcde'):
		sa = sorted(arr.items(), key=lambda x: x[1][i])
		sc = 0
		curr = 0
		while sa:
			el = sa.pop()
			sc += el[1][i]
			if sc <= 0:
				break
			curr += 1
		ans = max(ans, curr)
	print(ans)


def solve():
	n = int(input())
	words = [input() for i in range(n)]
	ans = 0
	for ch in 'abcde':
		cnt = sorted([2 * word.count(ch) - len(word) for word in words])
		(balance, res) = (0, 0)
		for k in cnt[::-1]:
			balance += k
			res += 1
			if balance <= 0:
				res -= 1
				break
		ans = max(ans, res)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())

def solve(arr, letter):
	di = {}
	for word in arr:
		c = 0
		for let in word:
			if let == letter:
				c = c + 1
			else:
				c = c - 1
		di[c] = di.get(c, 0) + 1
	cur = 0
	res = 0
	for i in sorted(di.keys(), reverse=True):
		for j in range(di[i]):
			if cur + i <= 0:
				break
			else:
				cur = cur + i
				res = res + 1
	return res
for _ in range(t):
	n = int(input())
	arr = []
	for _ in range(n):
		s = input()
		arr.append(s)
	lets = ['a', 'b', 'c', 'd', 'e']
	ans = 0
	for let in lets:
		ans = max(ans, solve(arr, let))
	print(ans)


def find(words, letter):
	new_words = []
	for i in words:
		new_words.append(2 * i.count(letter) - len(i))
	new_words.sort()
	total = 0
	count = 0
	while new_words:
		diff = new_words.pop()
		if total + diff > 0:
			total += diff
			count += 1
	return count

def solve(words, n, ans):
	max_val = 0
	for i in range(5):
		letter = chr(ord('a') + i)
		max_val = max(max_val, find(words, letter))
	ans.append(str(max_val))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		words = []
		for j in range(n):
			words.append(input())
		solve(words, n, ans)
	print('\n'.join(ans))
main()


def count(w, letter):
	composition = []
	for word in w:
		c = word.count(letter)
		composition.append([c, len(word) - c])
	composition = sorted(composition, key=lambda x: x[0] - x[1], reverse=True)
	num = [0, 0]
	ans = 0
	for (i, v) in enumerate(composition):
		num[0] += v[0]
		num[1] += v[1]
		if num[0] > num[1]:
			ans += 1
		else:
			return ans
	return ans
for _ in range(int(input())):
	n = int(input())
	words = [input() for _i in range(n)]
	print(max([count(words, let) for let in 'abcde']))


t = int(input())
for z in range(t):
	n = int(input())
	l = [input() for i in range(n)]
	ans = 0
	for a in 'abcde':
		count = []
		for i in l:
			c = 0
			for x in i:
				if x == a:
					c += 1
				else:
					c -= 1
			count.append(c)
		count.sort(reverse=True)
		temp = 0
		pn = 0
		for i in count:
			pn += i
			if pn > 0:
				temp += 1
			else:
				break
		ans = max(ans, temp)
	print(ans)


def solve(n, strs):
	ans = [0] * 5
	for tomax in range(5):
		tocheck = []
		for i in range(n):
			(sum1, sum2) = (0, 0)
			for j in range(len(strs[i])):
				if ord(strs[i][j]) - 97 == tomax:
					sum1 += 1
				else:
					sum2 += 1
			tocheck.append([sum1, sum2])
		tocheck.sort(key=lambda x: x[0] - x[1], reverse=True)
		tans = [0, 0]
		for i in range(n):
			tans[0] += tocheck[i][0]
			tans[1] += tocheck[i][1]
			if tans[0] > tans[1]:
				ans[tomax] = i + 1
	return max(ans)
for _ in range(int(input())):
	n = int(input())
	strs = []
	for i in range(n):
		strs.append(input())
	print(solve(n, strs))


import heapq

def get_ans(letter, words):
	heap = []
	for w in words:
		gc = w.count(letter)
		heapq.heappush(heap, len(w) - 2 * gc)
	cnt = 0
	ans = 0
	while len(heap):
		cnt += -heapq.heappop(heap)
		if cnt <= 0:
			return ans
		ans += 1
	return ans

def solve():
	n = int(input())
	words = [input() for _ in range(n)]
	ans = 0
	for l in 'abcde':
		ans = max(ans, get_ans(l, words))
	print(ans)
t = int(input())
for _ in range(t):
	solve()


from collections import Counter
from itertools import accumulate, takewhile
alphabet = 'abcde'
for _ in range(int(input())):
	deltas = {letter: [] for letter in alphabet}
	for i in range(int(input())):
		word = input()
		counter = Counter(word)
		for letter in alphabet:
			deltas[letter].append(2 * counter.get(letter, 0) - len(word))
	print(max((len(list(takewhile(lambda x: x > 0, accumulate(sorted(xs, reverse=True))))) for xs in deltas.values())))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	answer = 0
	n = int(sys.stdin.readline())
	strings = []
	for _ in range(n):
		seq = sys.stdin.readline().rstrip()
		strings.append(seq)
	for i in range(5):
		f = []
		for string in strings:
			(s, c) = (0, 0)
			for j in string:
				if chr(i + 97) == j:
					s += 1
				else:
					c += 1
			f.append(s - c)
		f.sort()
		k = sum(f)
		a = 0
		x = n
		while k <= 0 and a < n:
			k -= f[a]
			a += 1
			x -= 1
		if k > 0:
			answer = max(answer, x)
	print(answer)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'a1' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def S():
	return input().strip()

def print_list(l):
	print(' '.join(map(str, l)))
from heapq import *
from collections import deque as dq
from math import ceil, floor, sqrt, pow, factorial, log2
import bisect as bs
from collections import Counter
from itertools import permutations
for _ in range(N()):
	n = N()
	l = []
	string = 'abcde'
	for i in range(n):
		s = S()
		temp = [len(s)]
		c = Counter(s)
		for j in string:
			if j in c:
				temp.append(c[j])
			else:
				temp.append(0)
		l.append(temp)
	ans = 0
	for i in range(5):
		temp = l
		te = 0
		c1 = 0
		c2 = 0
		t2 = []
		for j in temp:
			if j[1 + i] > j[0] - j[1 + i]:
				c1 += j[1 + i]
				c2 += j[0] - j[1 + i]
				te += 1
			else:
				t2.append(j)
		t2 = sorted(t2, key=lambda x: x[0] - 2 * x[1 + i])
		for j in t2:
			c1 += j[1 + i]
			c2 += j[0] - j[1 + i]
			te += 1
			if c1 <= c2:
				te -= 1
				break
		ans = max(ans, te)
	print(ans)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(1, ii() + 1):
		n = ii()
		a = []
		for i in range(n):
			a.append(si())

		def get(c):
			x = []
			for i in range(n):
				c1 = 0
				for j in a[i]:
					if j == c:
						c1 += 1
					else:
						c1 -= 1
				x.append(c1)
			x.sort(reverse=True)
			s = 0
			for i in range(n):
				s += x[i]
				if s <= 0:
					return i
			return n
		mx = 0
		for i in ['a', 'b', 'c', 'd', 'e']:
			mx = max(mx, get(i))
		print(mx)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)

def charming():
	n = int(input())
	s = list()
	cnt = list(([0] * 6 for i in range(n)))
	for i in range(n):
		s.append(input())
		for ch in s[i]:
			cnt[i][ord(ch) - ord('a') + 1] += 1
		cnt[i][0] = len(s[i])
	res = 0
	for i in range(1, 6):
		cnt.sort(key=lambda x: 2 * x[i] - x[0], reverse=True)
		sum = 0
		j = 0
		while j < n:
			sum += 2 * cnt[j][i] - cnt[j][0]
			if sum <= 0:
				break
			j += 1
		res = max(res, j)
	print(res)
for t in range(int(input())):
	charming()


t = int(input())
for _ in range(t):
	n = int(input())

	def to_int(ch):
		return ord(ch) - ord('a')
	arr = [[None for _ in range(n)] for _ in range(5)]
	for i in range(n):
		s = input()
		ls = [[0, len(s)] for _ in range(5)]
		for x in s:
			ls[to_int(x)][0] += 1
		for j in range(5):
			arr[j][i] = tuple(ls[j])
	ans = 0
	for i in range(5):
		m = arr[i]
		m.sort(key=lambda x: -2 * x[0] + x[1])
		c = 0
		(sa, sb) = (0, 0)
		for (a, b) in m:
			sa += a
			sb += b
			if sb >= sa * 2:
				break
			c += 1
		ans = max(c, ans)
	print(ans)


def f(s, c):
	return 2 * s.count(c) - len(s)
t = int(input())
for i in range(t):
	n = int(input())
	words = []
	for j in range(n):
		word = input().strip()
		words.append(word)
		max_r = 0
	for c in ['a', 'b', 'c', 'd', 'e']:
		vals = sorted(list(map(lambda w: f(w, c), words)), reverse=True)
		if vals[0] <= 0:
			r = 0
		else:
			r = 1
			s = vals[0]
			while r < n and s > 0:
				s += vals[r]
				r += 1
			if s <= 0:
				r -= 1
		if r > max_r:
			max_r = r
	print(max_r)


ans = []
for _ in range(int(input())):
	n = int(input())
	a = [list(input().strip()) for _ in range(n)]
	m = 0
	for i in 'abcde':
		d = []
		s = 0
		c = 0
		for j in a:
			d.append(2 * j.count(i) - len(j))
		d.sort(reverse=True)
		for k in d:
			s += k
			if s > 0:
				c += 1
			else:
				break
		m = max([m, c])
	ans.append(m)
print('\n'.join(map(str, ans)))


for i in range(int(input())):
	n = int(input())
	v = []
	for j in range(n):
		v.append(input())
	ans = 0
	for j in ['a', 'b', 'c', 'd', 'e']:
		srt = []
		for h in range(len(v)):
			srt.append(2 * v[h].count(j) - len(v[h]))
		srt.sort(reverse=True)
		now = 0
		nowans = 0
		for h in srt:
			now += h
			if now > 0:
				nowans += 1
		ans = max(ans, nowans)
	print(ans)


import sys, os, io
from sys import stdin
import math
from collections import defaultdict
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def fun(char, l):
	char = chr(char + 97)
	new = []
	for i in range(len(l)):
		count = l[i].count(char)
		new.append([count - (len(l[i]) - count), count, len(l[i]) - count])
	new.sort(reverse=True)
	chrcount = 0
	othercount = 0
	totalcnt = 0
	for i in range(len(new)):
		(diff, cnt, othrcnt) = new[i]
		nchrcount = chrcount + cnt
		nothercount = othercount + othrcnt
		if nchrcount <= nothercount:
			return totalcnt
		chrcount = nchrcount
		othercount = nothercount
		totalcnt += 1
	return len(l)

def solve():
	n = ii()
	l = []
	for i in range(n):
		l.append(list(si()))
	ans = 0
	for i in range(5):
		ans = max(ans, fun(i, l))
	print(ans)
t = 1
t = ii()
for _ in range(t):
	solve()


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
INF = 10 ** 10

def solve(N, Words):
	max_score = 0
	for c in 'abcdefghijklmnopqrstuvwxyz':
		T = []
		for word in Words:
			n = word.count(c)
			T.append(n - (len(word) - n))
		T.sort(reverse=True)
		v = 0
		i = 0
		while i < N:
			if v + T[i] <= 0:
				score = i
				break
			v += T[i]
			i += 1
		else:
			score = N
		max_score = max(max_score, score)
	return max_score
T0 = int(input())
for _ in range(T0):
	N = int(input())
	Words = []
	for _ in range(N):
		Words.append(input())
	print(solve(N, Words))


n = int(input())
for i in range(n):
	x = int(input())
	arrIn = []
	for j in range(x):
		s = str(input())
		arrIn.append(s)
	wordsArr = []
	alphabet = ['a', 'b', 'c', 'd', 'e']
	for c in alphabet:
		freq = []
		for j in range(len(arrIn)):
			char = 0
			T = 0
			for k in range(len(arrIn[j])):
				if arrIn[j][k] == c:
					char = char + 1
				else:
					T = T + 1
			freq.append(char - T)
		freq.sort()
		freq.reverse()
		Total = 0
		words = 0
		for h in range(len(freq)):
			if freq[h] > 0:
				Total = Total + freq[h]
				words = words + 1
			elif Total + freq[h] > 0:
				Total = Total + freq[h]
				words = words + 1
			else:
				break
		wordsArr.append(words)
	max = 0
	for jkl in wordsArr:
		if jkl > max:
			max = jkl
	print(max)


import typing
import sys
from collections import Counter

def solve(n: int, a: typing.List[str]) -> typing.NoReturn:
	l = [len(s) for s in a]
	a = [Counter(s) for s in a]

	def calc_max(letter: str) -> int:
		b = [a[i][letter] * 2 - l[i] for i in range(n)]
		b.sort(reverse=1)
		s = 0
		for i in range(n):
			s += b[i]
			if s <= 0:
				return i
		return n
	mx = max((calc_max(letter) for letter in 'abcde'))
	print(mx)
	...

def main() -> typing.NoReturn:
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [sys.stdin.readline().rstrip() for _ in range(n)]
		solve(n, a)
		print()
main()


answers = []
for _ in range(int(input())):
	n = int(input())
	words = [input() for i in range(n)]
	ans = 0
	for i in 'abcde':
		counts = sorted([-len(word) + 2 * word.count(i) for word in words])[::-1]
		(su, n) = (0, 0)
		for count in counts:
			su += count
			n += 1
			if su <= 0:
				n -= 1
				break
		ans = max(ans, n)
	answers.append(ans)
for ans in answers:
	print(ans)


from itertools import product
import itertools
import math
import sys
import heapq
from collections import deque
MOD = 1000000000007

def find(parent, i):
	if parent[i] != i:
		parent[i] = find(parent, parent[i])
	return parent[i]

def union(parent, rank, xx, yy):
	x = find(parent, xx)
	y = find(parent, yy)
	if rank[x] > rank[y]:
		parent[y] = x
	elif rank[y] > rank[x]:
		parent[x] = y
	else:
		parent[y] = x
		rank[x] += 1
ans = 0
K = int(sys.stdin.readline().strip())
x = 0
y = 0
for _ in range(K):
	n = int(sys.stdin.readline().strip())
	l = []
	for _ in range(n):
		l.append(sys.stdin.readline().strip())
	ans = 0
	for k in ['a', 'b', 'c', 'd', 'e']:
		tl = []
		tt = [0, 0]
		for w in l:
			ttt = 0
			for c in w:
				if c == k:
					ttt += 1
				else:
					ttt -= 1
			tl.append(ttt)
		tl.sort(reverse=True)
		tans = 0
		tv = 0
		if tl[0] > 0:
			for v in tl:
				if tv + v > 0:
					tv += v
					tans += 1
				else:
					break
		ans = max(ans, tans)
	print(ans)


import sys
import os
import math
from io import BytesIO, IOBase
from collections import defaultdict, Counter, deque
import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	n = int(input())
	d = []
	l = []
	for j in range(n):
		s = input()
		l.append(len(s))
		cur = [0] * 5
		for j in s:
			ind = ord(j) - 97
			cur[ind] += 1
		d.append(cur)
	ans = 0
	for j in range(5):
		cur = []
		for k in range(n):
			cur.append(d[k][j] - (l[k] - d[k][j]))
		cur.sort(reverse=True)
		p = 0
		for j in range(n):
			if cur[j] + p > 0:
				p += cur[j]
			else:
				ans = max(ans, j)
				break
		else:
			ans = n
			break
	print(ans)


def naiveSolve():
	return
from collections import Counter
chars = 'abcde'

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		n = int(input())
		words = []
		for __ in range(n):
			words.append(Counter(input()))
		ans = 0
		for c in chars:
			arr = []
			for w in words:
				x = 0
				for c2 in chars:
					if c2 == c:
						x += w[c2]
					else:
						x -= w[c2]
				arr.append(x)
			arr.sort(reverse=True)
			t = 0
			for (i, x) in enumerate(arr):
				t += x
				if t > 0:
					ans = max(ans, i + 1)
		allans.append(ans)
	multiLineArrayPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(l, r):
	print('? {} {}'.format(l, r))
	sys.stdout.flush()
	return int(input())

def answerInteractive(x):
	print('! {}'.format(x))
	sys.stdout.flush()
inf = float('inf')
MOD = 998244353
from math import gcd, floor, ceil
for _abc in range(1):
	main()


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(iinp()):
	n = iinp()
	ml = [inp() for i in range(n)]
	poss = [0] * 5
	cnt = [0] * 5
	wordcnt = l2d(n, 5)
	for i in range(5):
		c = chr(97 + i)
		for (j, word) in enumerate(ml):
			if word.count(c) > len(word) / 2:
				poss[i] = 1
	for i in range(n):
		for c in ml[i]:
			x = ord(c) - 97
			cnt[x] += 1
			wordcnt[i][x] += 1
	mx = 0
	for i in range(5):
		if poss[i]:
			tmp = cnt.copy()
			tmpw = sorted(wordcnt, key=lambda x: 2 * x[i] - sum(x), reverse=True)
			f = 0
			while tmp[i] <= sum(tmp) / 2:
				tmp1 = tmpw.pop()
				for j in range(5):
					tmp[j] -= tmp1[j]
				f += 1
			mx = max(mx, n - f)
	print(mx)


import sys
t = int(input())
while t > 0:
	n = int(input())
	a = [list(input()) for i in range(n)]
	m = 0
	for i in 'abcde':
		d = []
		for j in a:
			d.append(2 * j.count(i) - len(j))
		d.sort(reverse=True)
		s = 0
		c = 0
		for k in d:
			s += k
			if s > 0:
				c += 1
			else:
				break
		m = max([m, c])
	print(m)
	t -= 1


from math import *
from collections import *
from functools import *
from bisect import *
from itertools import *
from heapq import *
import sys
inf = float('inf')
ninf = -float('inf')
ip = input
alphal = 'abcdefghijklmnopqrstuvwxyz'
alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mod = 10 ** 9 + 7

def ipl():
	return list(map(int, ip().split()))

def ipn():
	return int(ip())

def ipf():
	return float(ip())

def solve():
	wrds = []
	for _ in range(ipn()):
		s = ip()
		w = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
		for i in s:
			w[i] += 1
		wrds.append(w)
	r = 0
	for l in 'abcde':
		wrds.sort(key=lambda x: x[l] * 2 - sum(x.values()), reverse=True)
		c = cnt = 0
		x = 0
		for w in wrds:
			cnt = cnt - sum(w.values()) + 2 * w[l]
			c += 1
			if cnt > 0:
				x = c
		r = max(r, x)
	print(r)
t = ipn()
for _ in range(t):
	solve()


t = int(input())
while t > 0:
	n = int(input())
	s = []
	ans = 0
	for _ in range(0, n):
		x = input().strip()
		s.append(x)
	for i in 'abcde':
		d = []
		count = 0
		total = 0
		for j in s:
			diff = 2 * j.count(i) - len(j)
			d.append(diff)
		d.sort(reverse=True)
		for k in d:
			total += k
			if total > 0:
				count += 1
			else:
				break
		ans = max([ans, count])
	print(ans)
	t -= 1


mod = 10 ** 9 + 7

def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def calc(s):
	cnt = [0 for i in range(5)]
	for c in s:
		cnt[ord(c) - ord('a')] += 1
	ret = []
	for i in range(5):
		ret.append(2 * cnt[i] - sum(cnt))
	return ret

def solve(t_id):
	n = int(input())
	arr = []
	ans = 0
	for i in range(n):
		s = input()
		arr.append(calc(s))
	for i in range(5):
		v = []
		for j in range(n):
			v.append(arr[j][i])
		v.sort(reverse=True)
		sm = 0
		p = 0
		while p < n and sm + v[p] > 0:
			sm += v[p]
			p += 1
		ans = max(ans, p)
	print(ans)
t = 1
t = int(input())
for i in range(t):
	solve(i + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	words = [input() for _ in range(n)]
	alphabets = list('abcde')
	tot = 0
	answers = []
	for word in words:
		tot += len(word)
	for char in alphabets:
		counted = []
		for word in words:
			x = 0
			for c in word:
				if c == char:
					x += 1
			positive = x - (len(word) - x)
			counted.append((positive, word))
		counted.sort(reverse=True)
		temp_ans = 0
		letter_count = 0
		for word in counted:
			letter_count += word[0]
			if letter_count > 0:
				temp_ans += 1
			else:
				break
		answers.append(temp_ans)
	final_result = max(answers)
	print(final_result)


def solve(words):
	freq = [[0] * 6 for i in range(len(words))]
	for i in range(len(words)):
		freq[i][0] = words[i].count('a')
		freq[i][1] = words[i].count('b')
		freq[i][2] = words[i].count('c')
		freq[i][3] = words[i].count('d')
		freq[i][4] = words[i].count('e')
		freq[i][5] = len(words[i])
	ans = 0
	for i in range(5):
		freq.sort(key=lambda x: x[i] - (x[5] - x[i]), reverse=True)
		cnt = 0
		rest = 0
		miku = 0
		for j in range(len(words)):
			tmp = freq[j][i]
			cnt += tmp
			rest += freq[j][5] - tmp
			miku += 1
			if cnt > rest:
				ans = max(ans, miku)
	return ans
for t in range(int(input())):
	n = int(input())
	words = []
	for i in range(n):
		words.append(input())
	print(solve(words))


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()

def solve():
	n = int(input())
	strings = []
	for i in range(n):
		strings.append(input())
	f = [[] for _ in range(5)]
	const = ord('a')
	for i in range(5):
		f[i] = sorted([2 * word.count(chr(i + const)) - len(word) for word in strings], key=lambda x: -x)
	ans = 0
	for i in range(5):
		if f[i][0] <= 0:
			continue
		c = f[i][0]
		cnt = 0
		while c > 0:
			cnt += 1
			if cnt == n:
				break
			c += f[i][cnt]
		ans = max(cnt, ans)
	print(ans)
for _ in range(int(input())):
	solve()


def f(s, x):
	n = len(s)
	max1 = 0
	res = 0
	ans = [0] * n
	for i in range(n):
		ans[i] = 0
		for j in s[i]:
			if j == x:
				ans[i] += 1
				res += 1
			else:
				ans[i] -= 1
				res -= 1
	ans = sorted(ans)
	i = 0
	while i < n:
		if res > 0:
			break
		res -= ans[i]
		i += 1
	max1 = max(max1, n - i)
	return max1
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		s = input()
		a.append(s)
	ans = max(f(a, 'a'), f(a, 'b'), f(a, 'c'), f(a, 'd'), f(a, 'e'))
	print(ans)


import sys, math
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
mod = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def li():
	return list(map(int, input().split()))

def f(n, N, cnt):
	lst = []
	for i in range(N):
		a = 0
		b = 0
		for j in range(5):
			if j == n:
				a += cnt[i][j]
			else:
				b += cnt[i][j]
		lst.append([a, b])
	lst.sort(reverse=True, key=lambda x: x[0] - x[1])
	x = 0
	a = 0
	b = 0
	for (i, j) in lst:
		a += i
		b += j
		if b >= a:
			break
		x += 1
	return x
t = int(input())
for _ in range(t):
	N = int(input())
	words = [input() for _ in range(N)]
	cnt = []
	for i in words:
		tmp = [0] * 5
		for w in i:
			tmp[ord(w) - 97] += 1
		cnt.append(tmp)
	ans = 0
	for i in range(5):
		ans = max(ans, f(i, N, cnt))
	print(ans)


from collections import defaultdict
from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline

def S():
	return input()

def I():
	return int(S())

def M():
	return map(int, S().split())

def L():
	return list(M())
t = int(input())
for p in range(t):
	n = I()
	words = []
	for i in range(n):
		words.append(list(S()[:-1]))
	table = [[0] * 6 for _ in range(n)]
	letters = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}
	for (idx, i) in enumerate(words):
		for j in i:
			table[idx][letters[j]] += 1
			table[idx][5] += 1
	ans = 0
	for i in range(5):
		freq = []
		for j in range(n):
			diff = table[j][i] - (table[j][5] - table[j][i])
			freq.append(diff)
		freq.sort(reverse=True)
		p = 0
		curr = 0
		for z in range(n):
			curr += freq[z]
			if curr > 0:
				p += 1
			else:
				break
		ans = max(ans, p)
	print(ans)


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
MOD = 1000000007

def si():
	return input()

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())

def sout(v):
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def sieve(n):
	primes = []
	least_prime_divs = [0] * (n + 1)
	for i in range(2, n + 1):
		if not least_prime_divs[i]:
			least_prime_divs[i] = i
			primes.append(i)
		for p in primes:
			if i * p > n or p > least_prime_divs[i]:
				break
			least_prime_divs[i * p] = p
	return primes
t = ii()
while t:
	t -= 1
	n = ii()
	a = []
	for _ in range(n):
		a.append(si())
	curr = 0
	diff = [0 for _ in range(n)]
	ans = 0
	for curr in range(5):
		for i in range(n):
			diff[i] = a[i].count(chr(curr + 97)) * 2 - len(a[i])
		diff.sort(reverse=True)
		s = c = 0
		for i in range(n):
			if s + diff[i] <= 0:
				break
			s += diff[i]
			c += 1
		ans = max(ans, c)
	print(ans)


from collections import Counter
from math import *
import sys
mod = 1000000007

def pro(arr):
	n = len(arr)
	freq = []
	for i in range(n):
		freq.append([0] * 5)
	cand = [0] * n
	for i in range(n):
		maxi = 0
		for j in arr[i]:
			x = ord(j) - 97
			freq[i][x] += 1
		c1 = max(freq[i])
		if c1 <= sum(freq[i]) - c1:
			cand[i] = -1
		else:
			ind = freq[i].index(c1)
			cand[i] = ind
	fin = 0
	for p in range(5):
		temp = []
		for i in range(n):
			temp.append(freq[i][p] - (sum(freq[i]) - freq[i][p]))
		temp.sort(reverse=True)
		c = 0
		sumi = 0
		for i in temp:
			sumi += i
			if sumi > 0:
				c += 1
		fin = max(fin, c)
	print(fin)

def check(a, b, k):
	temp = [0] * 5
	for i in range(5):
		temp[i] = a[i] + b[i]
	c1 = sum(temp)
	return temp[k] > c1 - temp[k]
t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for j in range(n):
		arr.append(input())
	pro(arr)


from sys import *
input = stdin.readline
from bisect import *
import math
from collections import *
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	temp = []
	length = []
	for _ in range(n):
		s = input()[:-1]
		length.append(len(s))
		cnt = Counter(s)
		temp.append(cnt)
	maxx = 0
	for h in range(97, 97 + 5):
		gf = chr(h)
		fora = []
		for i in range(n):
			x = length[i] - temp[i][gf]
			y = temp[i][gf]
			fora.append([x - y, (y, x)])
		fora.sort(key=lambda x: x[0])
		suma = 0
		sumo = 0
		cnt = 0
		for i in fora:
			if i[0] < 0:
				suma += i[1][0]
				sumo += i[1][1]
				cnt += 1
		for i in fora:
			if i[0] >= 0 and suma + i[1][0] > sumo + i[1][1]:
				suma += i[1][0]
				sumo += i[1][1]
				cnt += 1
		maxx = max(cnt, maxx)
	print(maxx)


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

def SieveOfEratosthenes(n=10000):
	p = 2
	c = 0
	while p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				prime[i] = False
		p += 1

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def binarySearch(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
for ik in range(int(input())):

	def sub(arr):
		arr.sort(reverse=True)
		su = 0
		ans = 0
		for i in range(len(arr)):
			su += arr[i]
			if su > 0:
				ans = i + 1
		return ans
	n = int(input())
	word = []
	for i in range(n):
		word.append(list(input()))
	ans = 0

	def find(a):
		arr = []
		for i in range(len(word)):
			w = 0
			for j in word[i]:
				if ord(j) - 97 == a:
					w += 1
				else:
					w -= 1
			arr.append(w)
		return sub(arr)
	for i in range(5):
		ans = max(ans, find(i))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		temp = [0, 0, 0, 0, 0, 0]
		st = input()
		for j in st:
			if j == 'a':
				temp[0] += 1
			elif j == 'b':
				temp[1] += 1
			elif j == 'c':
				temp[2] += 1
			elif j == 'd':
				temp[3] += 1
			elif j == 'e':
				temp[4] += 1
		temp[-1] = sum(temp)
		arr.append(temp)
	ans = 0
	for i in range(5):
		c = []
		loc = 0
		count = 0
		for k in range(len(arr)):
			c.append(2 * arr[k][i] - arr[k][-1])
		c.sort(reverse=True)
		for j in c:
			if loc + j > 0:
				count += 1
				loc += j
			else:
				break
		ans = max(ans, count)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = []
	y = [[0 for i in range(5)] for j in range(n)]
	for i in range(n):
		s = input()
		for j in s:
			y[i][ord(j) - 97] += 1
	x = ['a', 'b', 'c', 'd', 'e']
	ans = []
	for i in range(5):
		z = []
		for j in range(n):
			z.append(2 * y[j][i] - sum(y[j]))
		z.sort(reverse=True)
		s = 0
		e = 0
		for m in range(n):
			if s + z[m] > 0:
				e += 1
				s += z[m]
			else:
				break
		ans.append(e)
	print(max(ans))


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	A = ord('a')
	b = [0] * 5
	r = [0] * 5
	d = [[] for i in range(5)]
	for i in range(n):
		c = [0] * 5
		for v in input().strip():
			c[ord(v) - A] += 1
		l = sum(c)
		for j in range(5):
			v = 2 * c[j] - l
			if v >= 0:
				b[j] += v
				r[j] += 1
			else:
				d[j].append(-v)
	for j in range(5):
		if b[j] == 0:
			r[j] = 0
		else:
			d[j].sort()
			for v in d[j]:
				if b[j] - v > 0:
					b[j] -= v
					r[j] += 1
				else:
					break
	print(max(r))
for i in range(int(input())):
	solve()


from collections import Counter
T = int(input())
for _ in range(T):
	n = int(input())
	W = []
	for _ in range(n):
		w = input()
		W.append([w, Counter(w)])
	best = 0
	for l in ['a', 'b', 'c', 'd', 'e']:
		W.sort(key=lambda e: len(e[0]) - 2 * e[1][l])
		size = 0
		d = 0
		for (w, c) in W:
			v = len(w) - 2 * c[l]
			if d + v < 0:
				size += 1
				d += v
			else:
				break
		best = max(best, size)
	print(best)


def process_word(word):
	count = [0, 0, 0, 0, 0]
	for i in word:
		if i == 'a':
			count[0] += 1
		elif i == 'b':
			count[1] += 1
		elif i == 'c':
			count[2] += 1
		elif i == 'd':
			count[3] += 1
		else:
			count[4] += 1
	s = sum(count)
	return [2 * i - s for i in count]

def process(n, words):
	counts = []
	to_return = [0] * 5
	for i in words:
		counts.append(process_word(i))
	for i in range(5):
		counts.sort(key=lambda x: x[i], reverse=True)
		if counts[0][i] < 1:
			pass
		else:
			counter = 1
			index = 1
			negative = counts[0][i]
			while index < n:
				negative += counts[index][i]
				index += 1
				if negative > 0:
					counter += 1
				else:
					break
			to_return[i] = counter
	return max(to_return)
t = int(input())
for i in range(t):
	n = int(input())
	words = []
	for j in range(n):
		words.append(input())
	print(process(n, words))


def count_symbols(s):
	d = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
	for x in s:
		d[x] += 1
	return list(d.values())

def solve(a, n):
	symb_am = []
	for i in range(n):
		symb_am.append([2 * x - len(a[i]) for x in count_symbols(a[i])])
	mx = 0
	for ltr in range(5):
		s = sorted(symb_am, key=lambda x: x[ltr], reverse=True)
		count = 0
		for i in range(n):
			count += s[i][ltr]
			if count <= 0:
				break
		else:
			return n
		if i > mx:
			mx = i
	return mx
amount = int(input())
res = []
for i in range(amount):
	n = int(input())
	a = []
	for j in range(n):
		a.append(input())
	res.append(solve(a, n))
print('\n'.join(map(str, res)))


import sys
from collections import Counter
input = sys.stdin.readline

def count(s):
	d = {}
	for i in s:
		d[i] = d.get(i, 0) + 1
	return d

def get_num(l):
	x = 0
	count = 0
	for i in l:
		if x + i > 0:
			x += i
			count += 1
	return count
for _ in range(int(input())):
	n = int(input())
	a = [''] * n
	for mn in range(n):
		a[mn] = input().strip()
	store = [{}] * len(a)
	for i in range(len(a)):
		store[i] = (count(a[i]), len(a[i]))
	a_sto = [0] * len(a)
	for i in range(len(a)):
		a_sto[i] = 2 * store[i][0].get('a', 0) - store[i][1]
	a_sto.sort(reverse=True)
	b_sto = [0] * len(a)
	for i in range(len(a)):
		b_sto[i] = 2 * store[i][0].get('b', 0) - store[i][1]
	b_sto.sort(reverse=True)
	c_sto = [0] * len(a)
	for i in range(len(a)):
		c_sto[i] = 2 * store[i][0].get('c', 0) - store[i][1]
	c_sto.sort(reverse=True)
	d_sto = [0] * len(a)
	for i in range(len(a)):
		d_sto[i] = 2 * store[i][0].get('d', 0) - store[i][1]
	d_sto.sort(reverse=True)
	e_sto = [0] * len(a)
	for i in range(len(a)):
		e_sto[i] = 2 * store[i][0].get('e', 0) - store[i][1]
	e_sto.sort(reverse=True)
	print(max(get_num(a_sto), get_num(b_sto), get_num(c_sto), get_num(d_sto), get_num(e_sto)))


al = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}

def solve(strings):
	amits = []
	for s in strings:
		temp = [0, 0, 0, 0, 0]
		for c in s:
			temp[al[c]] += 1
		amits.append(temp)
	best = 0
	for i in range(5):
		amits.sort(key=lambda x: x[i] - (sum(x) - x[i]), reverse=True)
		good = 0
		bad = 0
		first = 1
		amount = 0
		result = 0
		while (good > bad or first) and amount < len(strings):
			first = 0
			tot = sum(amits[amount])
			good += amits[amount][i]
			bad += tot - amits[amount][i]
			if good > bad:
				result += 1
				amount += 1
		if result > best:
			best = result
	return best
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	print(solve(a))


def Funtion(word, char):
	arrNum = [0, 0, 0, 0, 0]
	for c in word:
		arrNum[ord(c) - 97] += 1
	a = 2 * arrNum[ord(char) - 97]
	b = len(word)
	return a - b

def FindMaxWords(arr, char):
	arrFuntion = []
	for word in arr:
		arrFuntion.append(Funtion(word, char))
	(arrFuntion, arr) = zip(*sorted(zip(arrFuntion, arr)))
	count = 0
	Sum = 0
	arrFuntion = arrFuntion[::-1]
	for i in range(len(arrFuntion)):
		Sum += arrFuntion[i]
		if Sum > 0:
			count += 1
		else:
			return count
	return count
t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for word in range(n):
		new_word = input()
		arr.append(new_word)
	ans = FindMaxWords(arr, 'a')
	for code in range(98, 102):
		val = FindMaxWords(arr, chr(code))
		if val > ans:
			ans = val
	print(ans)


from collections import defaultdict

def solve(pos):
	ns = sorted(s, key=lambda x: (x[pos] - (sum(x) - x[5] - x[pos]), x[5]), reverse=True)
	c = 0
	tl = 0
	cans = 0
	ans = 0
	for j in ns:
		c += j[pos]
		tl += sum(j) - j[-1]
		cans += 1
		if c >= tl // 2 + 1:
			ans = max(cans, ans)
		else:
			break
	return ans
for i in range(int(input())):
	n = int(input())
	s = []
	for j in range(n):
		d = defaultdict(lambda : 0)
		a = input()
		for k in a:
			d[k] += 1
		count = [d['a'], d['b'], d['c'], d['d'], d['e'], j]
		s.append(count)
	ans = 0
	for j in range(5):
		ans = max(solve(j), ans)
	print(ans)


t = int(input())

def get_ans(arr, val):
	li = []
	for word in arr:
		(cnt1, cnt2) = (0, 0)
		for ch in word:
			if ch == val:
				cnt1 += 1
			else:
				cnt2 += 1
		li.append([cnt1, cnt2, cnt1 - cnt2])
	li = sorted(li, key=lambda x: x[2], reverse=True)
	rem = 0
	ans = 0
	for l in li:
		dif = l[2]
		if dif > 0:
			ans += 1
			rem += dif
		elif rem + dif > 0:
			rem += dif
			ans += 1
		else:
			break
	return ans
while t:
	n = int(input())
	arr = []
	while n:
		arr.append(input())
		n -= 1
	print(max(get_ans(arr, 'a'), get_ans(arr, 'b'), get_ans(arr, 'c'), get_ans(arr, 'd'), get_ans(arr, 'e')))
	t -= 1


def pretty_p(w):
	return ''.join(('a' * w[1], 'b' * w[2], 'c' * w[3], 'd' * w[4], 'e' * w[5]))
words = []

def five_uple(word):
	uple = [0] * 6
	for w in word:
		uple[ord(w) - ord('a') + 1] += 1
	uple[0] = len(word)
	return uple

def solve():
	global words
	n = int(input())
	words = [five_uple(input()) for _ in range(n)]
	words_in_interesting_story = 0
	for index in range(1, 6):
		words_in_this_story = 0
		total_letters = 0
		total_index_letter = 0
		sorter = lambda x: 2 * x[index] - x[0]
		words.sort(key=sorter, reverse=True)
		for i in range(n):
			total_letters += words[i][0]
			total_index_letter += words[i][index]
			if 2 * total_index_letter <= total_letters:
				break
			words_in_this_story += 1
		words_in_interesting_story = max(words_in_interesting_story, words_in_this_story)
	return words_in_interesting_story
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	s = []
	ans = 0
	a = [[0 for x in range(5)] for y in range(n)]
	for i in range(n):
		s.append(list(input()))
	for i in range(n):
		c = [0] * 26
		l = len(s[i])
		for j in range(l):
			c[ord(s[i][j]) - 97] += 1
		for k in range(5):
			a[i][k] = 2 * c[k] - l
	for k in range(5):
		b = [0] * n
		v = 0
		an = 0
		for i in range(n):
			b[i] = a[i][k]
		b.sort(reverse=True)
		for i in range(n):
			v += b[i]
			if v <= 0:
				break
			an += 1
		if an > ans:
			ans = an
	print(ans)


import sys
input = sys.stdin.readline
from collections import Counter, defaultdict
for _ in range(int(input())):
	n = int(input())
	A = [input()[:-1] for _ in range(n)]
	ans = 0
	for c in 'abcde':
		cur = sorted(A, key=lambda x: 2 * x.count(c) - len(x), reverse=True)
		cnt = Counter()
		tot = 0
		tmp = 0
		for w in cur:
			cnt += Counter(w)
			tot += len(w)
			if cnt[c] * 2 > tot:
				tmp += 1
			else:
				break
		ans = max(ans, tmp)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	storage = []
	for __ in range(n):
		word = input()
		wl = len(word)
		counter = [0] * 5
		for i in range(wl):
			counter[ord(word[i]) - 97] += 1
		final_counter = [0] * 5
		for i in range(5):
			final_counter[i] = 2 * counter[i] - wl
		storage.append(final_counter)
	ans = 0
	for j in range(5):
		v = []
		count = 0
		minians = 0
		for i in range(n):
			if storage[i][j] > 0:
				count = count + storage[i][j]
				minians += 1
			else:
				v.append(storage[i][j])
		v.sort(reverse=True)
		p = 0
		ll = n - minians
		while p < ll and count + v[p] > 0:
			count = count + v[p]
			minians += 1
			p = p + 1
		ans = max(ans, minians)
	print(ans)


def interestingStory(words):
	wc = []
	best_res = 0
	for char in 'abcde':
		for word in words:
			wc.append(word.count(char) * 2 - len(word))
		wc.sort(reverse=True)
		(p, res) = (0, 0)
		for k in wc:
			p += k
			if p > 0:
				res += 1
			else:
				break
		if res > best_res:
			best_res = res
		wc = []
	return best_res
t = int(input())
for i in range(t):
	words = []
	n = int(input())
	for j in range(n):
		s = input()
		words.append(s)
	print(interestingStory(words))


from __future__ import print_function
import math
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = []
	x = []
	for i in range(n):
		l.append([0] * 6)
	for i in range(n):
		a = insr()
		l[i][5] = len(a)
		l[i][0] = a.count('a') - (l[i][5] - a.count('a'))
		l[i][1] = a.count('b') - (l[i][5] - a.count('b'))
		l[i][2] = a.count('c') - (l[i][5] - a.count('c'))
		l[i][3] = a.count('d') - (l[i][5] - a.count('d'))
		l[i][4] = a.count('e') - (l[i][5] - a.count('e'))
	for i in range(5):
		l.sort(key=lambda x: x[i], reverse=1)
		c = 0
		oc = 0
		mc = 0
		for j in range(n):
			if oc + (l[j][5] - l[j][i]) // 2 < mc + (l[j][5] + l[j][i]) // 2:
				c += 1
				oc += (l[j][5] - l[j][i]) // 2
				mc += (l[j][i] + l[j][5]) // 2
			else:
				break
		x.append(c)
	print(max(x))


def gcd(a, b):
	if a % b == 0:
		return b
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)
testcases = 1
testcases = int(input())
for _ in range(testcases):
	n = int(input())
	words = []
	for i in range(n):
		inp = str(input())
		words.append(inp)
	A = []
	for i in range(len(words)):
		x = words[i].count('a')
		A.append(2 * x - len(words[i]))
	A.sort()
	B = []
	for i in range(len(words)):
		x = words[i].count('b')
		B.append(2 * x - len(words[i]))
	B.sort()
	C = []
	for i in range(len(words)):
		x = words[i].count('c')
		C.append(2 * x - len(words[i]))
	C.sort()
	D = []
	for i in range(len(words)):
		x = words[i].count('d')
		D.append(2 * x - len(words[i]))
	D.sort()
	E = []
	for i in range(len(words)):
		x = words[i].count('e')
		E.append(2 * x - len(words[i]))
	E.sort()
	maxi = 0
	suma = 0
	count = 0
	for i in range(len(A) - 1, -1, -1):
		suma += A[i]
		count += 1
		if suma <= 0:
			maxi = max(maxi, count - 1)
			break
	else:
		maxi = max(maxi, count)
	suma = 0
	count = 0
	for i in range(len(B) - 1, -1, -1):
		suma += B[i]
		count += 1
		if suma <= 0:
			maxi = max(maxi, count - 1)
			break
	else:
		maxi = max(maxi, count)
	suma = 0
	count = 0
	for i in range(len(C) - 1, -1, -1):
		suma += C[i]
		count += 1
		if suma <= 0:
			maxi = max(maxi, count - 1)
			break
	else:
		maxi = max(maxi, count)
	suma = 0
	count = 0
	for i in range(len(D) - 1, -1, -1):
		suma += D[i]
		count += 1
		if suma <= 0:
			maxi = max(maxi, count - 1)
			break
	else:
		maxi = max(maxi, count)
	suma = 0
	count = 0
	for i in range(len(E) - 1, -1, -1):
		suma += E[i]
		count += 1
		if suma <= 0:
			maxi = max(maxi, count - 1)
			break
	else:
		maxi = max(maxi, count)
	print(maxi)


from collections import Counter
from sys import stdin
input = stdin.readline

def seq(ch):
	new_seq = [2 * word[0][ch] - word[1] for word in words]
	new_seq.sort(reverse=True)
	amt = 0
	num_word = 0
	for i in new_seq:
		if amt + i > 0:
			amt += i
			num_word += 1
	return num_word

def func():
	print(max(seq('a'), seq('b'), seq('c'), seq('d'), seq('e')))
for _ in range(int(input())):
	ans = 0
	n = int(input())
	words = []
	for __ in range(n):
		word = input().strip()
		words.append((Counter(word), len(word)))
	func()


from sys import stdin
from collections import defaultdict as dict, Counter
input = lambda : stdin.readline().strip()
linput = lambda : [*map(int, input().split())]
output = []

def lprint(*x):
	output.append(' '.join(map(str, x)))

def main():
	d = [input() for _ in ' ' * int(input())]
	a = [*map(Counter, d)]
	ans = 0
	for w in 'abcde':
		a.sort(key=lambda x: 2 * x[w] - sum(x.values()), reverse=True)
		s1 = a[0][w]
		s2 = sum(a[0].values()) - s1
		i = 1
		while s2 < s1:
			ans = max(i, ans)
			if i == len(a):
				lprint(i)
				return
			s1 += a[i][w]
			s2 += sum(a[i].values()) - a[i][w]
			i += 1
	lprint(ans)
for _ in ' ' * int(input()):
	main()
print(*output, sep='\n')


t = int(input())
for asifjalfjalfjaflj in range(t):
	n = int(input())
	words = []
	for _ in range(n):
		word = input()
		words.append(word)
	max_count = 0
	for char in 'abcde':
		temp = []
		for word in words:
			temp.append(2 * word.count(char) - len(word))
		temp.sort(reverse=True)
		if temp[0] <= 0:
			continue
		count = 0
		local_max = 0
		for num in temp:
			local_max += num
			if local_max > 0:
				count += 1
			else:
				break
		max_count = max(max_count, count)
	print(max_count)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	lis = []
	for _ in range(n):
		lis.append(input().strip())
	ans = -1
	for check in ['a', 'b', 'c', 'd', 'e']:
		counts = []
		for word in lis:
			count = 0
			for i in word:
				if i == check:
					count += 1
				else:
					count -= 1
			counts.append(count)
		counts = sorted(counts, reverse=True)
		count = 0
		s = 0
		for i in counts:
			s += i
			if s > 0:
				count += 1
			else:
				break
		ans = max(ans, count)
	print(ans)
for _ in range(int(input())):
	solve()


r = list('abcde')
for _ in range(int(input())):
	l = [[], [], [], [], []]
	for y in range(int(input())):
		t = input()
		tl = len(t)
		for x in range(5):
			p = t.count(r[x])
			l[x].append(p - (tl - p))
	p = 0
	for x in l:
		c = 0
		ans = 0
		t = []
		for y in x:
			if y > 0:
				ans += 1
				c += y
			else:
				t.append(y)
		t.sort(reverse=True)
		for x in t:
			if x + c > 0:
				ans += 1
				c += x
			else:
				break
		p = max(p, ans)
	print(p)


import atexit, io, sys, collections, math, heapq, fractions, copy, os, functools
import sys
import random
import collections
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def f(wis):
	cc = [[collections.Counter(wi), len(wi)] for wi in wis]
	alphabet = map(chr, range(ord('a'), ord('e') + 1))
	ans = 0
	for letter in alphabet:
		cc.sort(key=lambda x: -(2 * x[0][letter] - x[1]))
		cumul = 0
		count = 0
		for x in cc:
			cumul += 2 * x[0][letter] - x[1]
			if cumul > 0:
				count += 1
				ans = max(count, ans)
			else:
				break
	return ans
	return 0
for _ in range(int(input())):
	n = int(input())
	wis = [input() for i in range(n)]
	print(f(wis))


import math
T = int(input())
for t in range(T):
	words = []
	p = pow(10, 6)
	n = int(input())
	for _ in range(n):
		words.append(input())
	counter = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
	lists = {'a': [], 'b': [], 'c': [], 'd': [], 'e': []}
	for word in words:
		d = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
		for w in word:
			d[w] += 1
		for letter in lists:
			lists[letter].append((len(word) - d[letter] - d[letter], len(word) - d[letter], p - d[letter]))
		for letter in counter:
			counter[letter] += d[letter]
	total = 0
	for i in counter:
		total += counter[i]
	answers = []
	for letter in lists:
		l_ctr = counter[letter]
		t_ctr = total - l_ctr
		ans_ctr = len(words)
		req_list = list(lists[letter])
		req_list.sort()
		for i in range(len(req_list)):
			if l_ctr > t_ctr:
				break
			ele = req_list.pop()
			l_ctr -= p - ele[2]
			t_ctr -= ele[1]
			ans_ctr -= 1
		answers.append(ans_ctr)
	a1 = max(answers)
	print(a1)


t = int(input())
letter = ['a', 'b', 'c', 'd', 'e']
for case in range(t):
	n = int(input())
	story = []
	interesting = 0
	for i in range(n):
		story.append(input())
	for a in letter:
		pq = []
		for s in story:
			pq.append(len(s) - 2 * s.count(a))
		pq = sorted(pq)
		(tracker, flag) = (0, 0)
		for t in range(n):
			tracker += pq[t]
			if tracker < 0:
				flag += 1
			else:
				break
		interesting = max(interesting, flag)
	print(interesting)


from collections import Counter
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	ss = []
	for _ in range(n):
		ss.append(input())
	max_total = 0
	for key in ['a', 'b', 'c', 'd', 'e']:
		total = 0
		temps = []
		sss = ss.copy()
		for i in range(len(sss)):
			count_el = sss[i].count(key)
			left = len(sss[i]) - count_el
			diff = count_el - left
			temps.append(diff)
		sss = sorted(zip(sss, temps), key=lambda x: x[1], reverse=True)
		b = 0
		if sss[0][1] > 0:
			total += 1
			b = sss[0][1]
		else:
			continue
		for i in range(1, len(sss)):
			(x, y) = (sss[i][0], sss[i][1])
			diff = b + y
			if diff >= 1:
				total += 1
				b = diff
			else:
				break
		max_total = max(max_total, total)
	print(max_total)


def solve(n, arr):
	total = 0
	store = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
	a = []
	b = []
	c = []
	d = []
	e = []
	for ele in arr:
		total = len(ele)
		store = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
		for char in ele:
			store[char] += 1
		a.append(2 * store['a'] - total)
		b.append(2 * store['b'] - total)
		c.append(2 * store['c'] - total)
		d.append(2 * store['d'] - total)
		e.append(2 * store['e'] - total)
	a.sort()
	b.sort()
	c.sort()
	d.sort()
	e.sort()
	best = 0
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += a[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += b[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += c[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += d[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	current = 0
	temp = 0
	for i in range(n - 1, -1, -1):
		current += e[i]
		if current > 0:
			temp += 1
		else:
			break
	best = max(best, temp)
	print(best)
	return
T = int(input())
while T:
	n = int(input())
	tempN = n
	arr = []
	while tempN:
		s = input()
		arr.append(s)
		tempN -= 1
	solve(n, arr)
	T -= 1


for _ in range(int(input())):
	n = int(input())
	words = []
	for i in range(n):
		words.append(input())
	w = ['a', 'b', 'c', 'd', 'e']
	ans = 0
	for i in range(5):
		tar = w[i]
		al = []
		for j in words:
			l = list(j)
			n1 = len(l)
			al.append(2 * l.count(tar) - n1)
		al.sort()
		al = al[::-1]
		flag = 0
		j = 0
		for j in range(1, n):
			al[j] = al[j - 1] + al[j]
			if al[j] <= 0:
				flag = 1
				break
		if flag == 0:
			if al[-1] > 0:
				j += 1
		if al[0] <= 0:
			j = 0
		ans = max(ans, j)
	print(ans)


import os
import sys
import time
from io import BytesIO, IOBase

def main():
	t = i_input()
	for tt in range(t):
		n = i_input()
		words = []
		for nn in range(n):
			c = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
			w = input()
			for l in w:
				c[l] += 1
			c['!'] = len(w)
			words.append(c)
		ans = 0
		for l in ('a', 'b', 'c', 'd', 'e'):
			w = []
			for word in words:
				w.append((word[l] * 2 - word['!'], word[l], word['!']))
			w.sort(reverse=True)
			sl = 0
			ll = 0
			for (i, ww) in enumerate(w):
				sl += ww[2]
				ll += ww[1]
				if ll * 2 <= sl:
					ans = max(ans, i)
					break
			else:
				ans = len(w)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def i_input():
	return int(input())

def l_input():
	return input().split()

def li_input():
	return list(map(int, l_input()))

def il_input():
	return list(map(int, l_input()))
TT = time.time()
main()


t = int(input())

def findCycle(start, offset, used, l):
	n = len(l)
	cur = start
	while 1:
		used[cur] = True
		next = l[(cur + offset) % n]
		if used[next]:
			return used
		cur = next

def calculateCycles(offset, l):
	n = len(l)
	used = [False for i in range(n)]
	tot = 0
	for i in range(n):
		if l[i] == (i + offset) % n:
			continue
		elif used[l[i]] == True:
			continue
		else:
			tot += 1
			used = findCycle(l[i], offset, used, l)
	return tot
for o in range(t):
	n = int(input())
	counts = [[] for i in range(5)]
	for i in range(n):
		d = {}
		l = input()
		m = len(l)
		for c in l:
			if c in d:
				d[c] = d[c] + 1
			else:
				d[c] = 1
		for j in range(5):
			c = chr(j + ord('a'))
			surplus = -m
			if c in d:
				surplus = 2 * d[c] - m
			counts[j].append(surplus)
	mx = 0
	for i in range(5):
		cur = counts[i]
		cur = sorted(cur)
		tot = 0
		ind = 0
		while 1:
			tot += cur[-1 - ind]
			if tot <= 0:
				break
			if ind == len(cur) - 1:
				mx = len(cur)
				break
			ind += 1
			mx = max(mx, ind)
	print(mx)


from collections import Counter

def score(w, letter):
	return counters[w][letter] - (len(w) - counters[w][letter])

def count_interesting_words(letter):
	words.sort(key=lambda w: -score(w, letter))
	beatiful_margin = 0
	for (i, w) in enumerate(words):
		beatiful_margin += score(w, letter)
		if beatiful_margin < 1:
			return i
	return len(words)
t = int(input())
for _ in range(t):
	n = int(input())
	words = [input() for _ in range(n)]
	counters = {word: Counter(word) for word in words}
	best_per_letter = [count_interesting_words(let) for let in 'abcde']
	print(max(best_per_letter))


from sys import stdin
from functools import cmp_to_key
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left
mod = 998244353
mod = 1000000007

def solve(we):
	n = iin()
	l = [input() for i in range(n)]
	a = [0] * 5
	ans = [0] * 5
	d = {i: [] for i in range(0, 5)}
	for s in l:
		count = [0] * 5
		for i in s:
			count[ord(i) - 97] += 1
		for i in range(5):
			if 2 * count[i] - len(s) >= 0:
				a[i] += 2 * count[i] - len(s)
				ans[i] += 1
			else:
				d[i].append(len(s) - 2 * count[i])
	for i in d:
		if a[i] == 0:
			ans[i] = 0
		else:
			d[i].sort()
			for j in d[i]:
				if a[i] - j > 0:
					a[i] -= j
					ans[i] += 1
				else:
					break
	print(max(ans))
qwe = 1
qwe = iin()
for _ in range(qwe):
	solve(_ + 1)


def solve():
	n = int(input())
	words = [input() for i in range(n)]
	ans = 0
	for ch in 'abcde':
		cnt = sorted([2 * word.count(ch) - len(word) for word in words])
		(balance, res) = (0, 0)
		for k in cnt[::-1]:
			balance += k
			res += 1
			if balance <= 0:
				res -= 1
				break
		ans = max(ans, res)
	print(ans)
t = int(input())
for _ in range(t):
	solve()
num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()


for _ in range(int(input())):
	n = int(input())
	A = []
	for i in range(n):
		A.append(input())
	ans = 0
	for i in range(5):
		B = []
		s = chr(ord('a') + i)
		for j in range(len(A)):
			B.append(2 * A[j].count(s) - len(A[j]))
		B.sort(reverse=True)
		su = 0
		for j in range(len(B)):
			su += B[j]
			if su > 0:
				ans = max(ans, j + 1)
			else:
				break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	occur = [[0 for _ in range(6)] for _ in range(n)]
	temp = [[] for _ in range(5)]
	for i in range(n):
		word = list(input())
		for letter in word:
			if letter == 'a':
				occur[i][0] += 1
			if letter == 'b':
				occur[i][1] += 1
			if letter == 'c':
				occur[i][2] += 1
			if letter == 'd':
				occur[i][3] += 1
			if letter == 'e':
				occur[i][4] += 1
			occur[i][5] += 1
		for j in range(5):
			occur[i][j] = 2 * occur[i][j] - occur[i][5]
			temp[j].append(occur[i][j])
	max = None
	for j in range(5):
		temp[j].sort(reverse=True)
		sum = 0
		count = 0
		for item in temp[j]:
			sum += item
			if sum <= 0:
				break
			else:
				count += 1
		if not max or max < count:
			max = count
	print(max)


from collections import Counter
for t in range(int(input())):
	n = int(input())
	words = []
	for i in range(n):
		words.append(input())
	wordf = [[0, 0, 0, 0, 0] for i in range(n)]
	tc = [0, 0, 0, 0, 0]
	for (i, word) in enumerate(words):
		cntr = Counter(word)
		for c in cntr:
			wordf[i][ord(c) - ord('a')] = cntr[c]
			tc[ord(c) - ord('a')] += cntr[c]
	max_w = 0
	for c in range(5):
		ws = n
		(cc, oc) = (tc[c], sum([tc[i] for i in range(5) if i != c]))
		wordf.sort(key=lambda x: x[c] - sum([x[i] for i in range(5) if i != c]))
		for wf in wordf:
			if cc > oc:
				break
			cc -= wf[c]
			oc -= sum([wf[i] for i in range(5) if i != c])
			ws -= 1
		max_w = max(ws, max_w)
	print(max_w)


def solve():
	n = int(input())
	s = []
	for i in range(n):
		t = input()
		s.append(t)
	ans = 0
	for i in range(0, 5):
		c = chr(ord('a') + i)
		a = []
		for j in s:
			diff = 0
			for k in j:
				if k == c:
					diff -= 1
				else:
					diff += 1
			a.append(diff)
		a.sort()
		sum = 0
		for i in range(len(a)):
			sum += a[i]
			if sum >= 0:
				break
			ans = max(ans, i + 1)
	print(ans)

def main():
	t = int(input())
	for i in range(t):
		solve()
main()


from sys import stdin
from io import StringIO
from collections import Counter
input = lambda : stdin.readline().strip()
linput = lambda : [*map(int, input().split())]
output = StringIO()

def lprint(*x):
	for v in x:
		output.write(str(v))
		output.write(' ')
	output.write('\n')

def main():
	d = [input() for _ in ' ' * int(input())]
	a = [*map(Counter, d)]
	ans = 0
	for w in 'abcde':
		a.sort(key=lambda x: 2 * x[w] - sum(x.values()), reverse=True)
		s1 = a[0][w]
		s2 = sum(a[0].values()) - s1
		i = 1
		while s2 < s1:
			ans = max(i, ans)
			if i == len(a):
				lprint(i)
				return
			s1 += a[i][w]
			s2 += sum(a[i].values()) - a[i][w]
			i += 1
	lprint(ans)
for _ in ' ' * int(input()):
	main()
print(output.getvalue())


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())

def solve(a):
	arr = []
	for i in range(n):
		c = 0
		for j in range(len(words[i])):
			if words[i][j] == a:
				c += 1
		arr.append(2 * c - len(words[i]))
	arr.sort(reverse=True)
	ans = 0
	if arr[0] <= 0:
		return 0
	for i in range(1, len(arr)):
		arr[i] += arr[i - 1]
		if arr[i] <= 0:
			return i
			break
	else:
		return len(arr)
while t:
	t -= 1
	n = int(input())
	words = []
	to = 0
	for i in range(n):
		s = input()
		to += len(s)
		words.append(s)
	ans = 0
	ans = max(solve('a'), ans)
	ans = max(solve('b'), ans)
	ans = max(solve('c'), ans)
	ans = max(solve('d'), ans)
	ans = max(solve('e'), ans)
	print(ans)


letters = ['a', 'b', 'c', 'd', 'e']
t = int(input())
results = []
for i in range(t):
	n = int(input())
	sequences = {}
	for letter in letters:
		sequences[letter] = [0] * n
	for j in range(n):
		word = input()
		length = len(word)
		for letter in letters:
			count = word.count(letter)
			sequences[letter][j] = 2 * count - length
	res = 0
	for letter in letters:
		sequences[letter].sort(reverse=True)
		current_count = sequences[letter][0]
		if current_count <= 0:
			continue
		j = 1
		while j < n and current_count + sequences[letter][j] >= 1:
			current_count += sequences[letter][j]
			j += 1
		res = max(res, j)
	results.append(res)
for i in range(t):
	print(results[i])


from typing import overload
testcase = int(input())
for _ in range(testcase):
	n = int(input())
	words = []
	s_a = []
	s_b = []
	s_c = []
	s_d = []
	s_e = []
	max_words = 0
	for i in range(n):
		s = input()
		words.append(s)
		ll = len(s)
		s_a.append(s.count('a') * 2 - ll)
		s_b.append(s.count('b') * 2 - ll)
		s_c.append(s.count('c') * 2 - ll)
		s_d.append(s.count('d') * 2 - ll)
		s_e.append(s.count('e') * 2 - ll)
	s_a.sort(reverse=True)
	s_b.sort(reverse=True)
	s_c.sort(reverse=True)
	s_d.sort(reverse=True)
	s_e.sort(reverse=True)
	k = [s_a, s_b, s_c, s_d, s_e]
	for i in k:
		if i[0] <= 0:
			continue
		temp_max_words = 0
		overhead = 0
		for j in i:
			overhead += j
			if overhead <= 0:
				break
			temp_max_words += 1
		max_words = max(max_words, temp_max_words)
	print(max_words)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
import bisect, string, math, time, functools, random, fractions
st = time.time()
from bisect import *
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 8
	n = random.randint(2, N)
	n = 6
	a = [(random.randint(1, 9), random.randint(1, 9)) for i in range(n)]
	return a

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(inp)
		a2 = solve(inp)
		if a1 != a2:
			print(inp)
			print('naive', a1)
			print('solve', a2)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
alp = [chr(ord('a') + i) for i in range(26)]

def primeFactor(N):
	(i, n) = (2, N)
	ret = {}
	(d, sq) = (2, 99)
	while i <= sq:
		k = 0
		while n % i == 0:
			(n, k, ret[i]) = (n // i, k + 1, k + 1)
		if k > 0 or i == 97:
			sq = int(n ** (1 / 2) + 0.5)
		if i < 4:
			i = i * 2 - 1
		else:
			(i, d) = (i + d, d ^ 6)
	if n > 1:
		ret[n] = 1
	return ret

def divisors(n):
	div = [1]
	for (i, j) in primeFactor(n).items():
		div = [i ** k * d for d in div for k in range(j + 1)]
	return div

def sieve(x):
	s = [i for i in range(x + 1)]
	p = 2
	while p * p <= x:
		if s[p] == p:
			for q in range(2 * p, x + 1, p):
				if s[q] == q:
					s[q] = p
		p += 1
	return s

def PrimeNumSet(N):
	M = int(N ** 0.5)
	seachList = [i for i in range(2, N + 1)]
	primes = []
	while seachList:
		if seachList[0] > M:
			break
		primes.append(seachList[0])
		tmp = seachList[0]
		seachList = [i for i in seachList if i % tmp != 0]
	return primes + seachList

def LCM(b, mo=10 ** 9 + 7):
	prs = PrimeNumSet(max(b))
	M = dict(zip(prs, [0] * len(prs)))
	for i in b:
		dc = primeFactor(i)
		for (j, k) in dc.items():
			M[j] = max(M[j], k)
	r = 1
	for (j, k) in M.items():
		if k != 0:
			r *= pow(j, k, mo)
			r %= mo
	return r

def extgcd(x, y):
	if y == 0:
		return (1, 0)
	(r0, r1, s0, s1) = (x, y, 1, 0)
	while r1 != 0:
		(r0, r1, s0, s1) = (r1, r0 % r1, s1, s0 - r0 // r1 * s1)
	return (s0, (r0 - s0 * x) // y, x * s0 + y * (r0 - s0 * x) // y)

def crt(rems, mods):
	n = len(rems)
	if n != len(mods):
		return NotImplemented
	(x, d) = (0, 1)
	for (r, m) in zip(rems, mods):
		(a, b, g) = extgcd(d, m)
		(x, d) = ((m * b * x + d * a * r) // g, d * (m // g))
		x %= d
	for (r, m) in zip(rems, mods):
		if r != x % m:
			return (-1, d)
	return (x, d)

def intsqrt(x):
	if x < 0:
		return NotImplemented
	rt = int(x ** 0.5) - 1
	while (rt + 1) ** 2 <= x:
		rt += 1
	return rt
show_flg = False
show_flg = True
d = dict(zip('abcde', range(5)))
for i in range(I()):
	ans = 0
	n = I()
	t = []
	for i in range(n):
		s = input()
		x = [0] * 5
		for j in s:
			x[d[j]] += 1
		t += (x + [sum(x)],)
	ans = 0
	for i in range(5):
		t.sort(key=lambda x: -x[i] + (x[5] - x[i]))
		tmp = a = 0
		for j in range(n):
			a += t[j][i] - (t[j][5] - t[j][i])
			if a < 1:
				break
			tmp = j + 1
		ans = max(ans, tmp)
	print(ans)


def sol():
	n = int(input())
	slowa = []
	for i in range(n):
		slowa.append(input())
	opcje = [[] for i in range(26)]
	for slowo in slowa:
		mapa = 26 * [0]
		suma = 0
		for znak in slowo:
			mapa[ord(znak) - ord('a')] += 1
			suma += 1
		for i in range(26):
			opcje[i].append(mapa[i] - (suma - mapa[i]))
	wyn = 0
	for i in range(26):
		opcje[i].sort(reverse=True)
		if opcje and opcje[i][0] > 0:
			p = opcje[i][0]
			ans = 1
		else:
			continue
		m = len(opcje[i])
		po = 1
		while po < m and p + opcje[i][po] > 0:
			p += opcje[i][po]
			ans += 1
			po += 1
		wyn = max(wyn, ans)
	print(wyn)

def main():
	for i in range(int(input())):
		sol()
main()


tt = int(input())
for _ in range(tt):
	n = int(input())
	ll = []
	calc = []
	for i in range(n):
		word = input()
		ll.append(word)
		num = [0] * 5
		for c in word:
			i = ord(c) - ord('a')
			num[i] += 1
		calc.append(num)
	w = [0] * 5
	for k in range(5):
		q = []
		for num in calc:
			q.append(sum(num) - 2 * num[k])
		q.sort()
		res = 0
		i = 0
		while i < n and res + q[i] < 0:
			res += q[i]
			i += 1
		w[k] = i
	print(max(w))


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = [[], [], [], [], []]
	for i in range(n):
		s = input()
		a = 0
		b = 0
		c = 0
		d = 0
		e = 0
		for j in range(len(s) - 1):
			x = s[j]
			if x == 'a':
				a += 1
			if x == 'b':
				b += 1
			if x == 'c':
				c += 1
			if x == 'd':
				d += 1
			if x == 'e':
				e += 1
		total = a + b + c + d + e
		l[0].append(a - total + a)
		l[1].append(b - total + b)
		l[2].append(c - total + c)
		l[3].append(d - total + d)
		l[4].append(e - total + e)
	som = 0
	for o in l:
		o.sort()
		c = 0
		r = 0
		ans = 0
		while len(o) > 0:
			ele = o.pop()
			if ele + c <= 0:
				break
			c += ele
			ans += 1
		som = max(som, ans)
	print(som)


from sys import stdin, stdout
print = stdout.write
input = stdin.readline
from collections import defaultdict
dictionary = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}

class Word:

	def __init__(self, word):
		self.abcde = [0, 0, 0, 0, 0]
		for x in word:
			self.abcde[dictionary[x]] += 1
		self.len = len(word)

	def difference(self, letter):
		return 2 * self.abcde[letter] - self.len

	def __repr__(self):
		return str(self.abcde)

def solve_test():
	n = int(input())
	words = [Word(input()[:-1]) for _ in range(n)]
	count = [0, 0, 0, 0, 0]
	for x in words:
		for i in range(5):
			count[i] += x.abcde[i]
	res = 0
	for i in range(5):
		words.sort(key=lambda word: word.difference(i), reverse=True)
		total = 0
		_res = 0
		for word in words:
			total += word.difference(i)
			if total > 0:
				_res += 1
			else:
				break
		res = max(_res, res)
	return res

def main(args=None):
	tests = int(input())
	for _ in range(tests):
		print(f'{solve_test()}\n')
main()


from collections import *
from math import *
TT = int(input())
for y in range(TT):
	n = int(input())
	lst = []
	for i in range(n):
		lst.append([0] * 5)
	for i in range(n):
		s = input()
		ln = len(s)
		lst[i][0] = s.count('a') * 2 - ln
		lst[i][1] = s.count('b') * 2 - ln
		lst[i][2] = s.count('c') * 2 - ln
		lst[i][3] = s.count('d') * 2 - ln
		lst[i][4] = s.count('e') * 2 - ln
	maxx = 0
	for i in range(5):
		temp = []
		for j in range(n):
			temp.append(lst[j][i])
		temp.sort(reverse=True)
		cc = 0
		for k in range(n):
			cc = cc + temp[k]
			if cc > 0:
				maxx = max(maxx, k + 1)
			else:
				break
	print(maxx)


t = int(input())

def func(alistpls, alistmin, res, pl):
	a = 0
	other = 0
	for i in alistpls:
		a += i[pl]
		other += i[5] - i[pl]
	i = 0
	while i < len(alistmin):
		if a + alistmin[i][pl] > other + alistmin[i][5] - alistmin[i][pl]:
			a += alistmin[i][pl]
			other += alistmin[i][5] - alistmin[i][pl]
		else:
			break
		i += 1
	res = max(res, i + len(alistpls))
	return res
for tc in range(t):
	n = int(input())
	strs = []
	for i in range(n):
		strs.append(list(input().rstrip()))
	occ = {}
	for i in range(1, n + 1):
		s = strs[i - 1]
		b = []
		for l in ['a', 'b', 'c', 'd', 'e']:
			b.append(s.count(l))
		b.append(sum(b))
		occ[i] = b
	comp = []
	for i in occ:
		comp.append(occ[i])
	alistpls = []
	alistmin = []
	for x in comp:
		if x[0] > x[5] - x[0]:
			alistpls.append(x)
		else:
			alistmin.append(x)
	alistpls.sort(key=lambda x: x[0] / x[5], reverse=True)
	alistmin.sort(key=lambda x: x[5] - x[0] - x[0])
	blistpls = []
	blistmin = []
	for x in comp:
		if x[1] > x[5] - x[1]:
			blistpls.append(x)
		else:
			blistmin.append(x)
	blistpls.sort(key=lambda x: x[1] / x[5], reverse=True)
	blistmin.sort(key=lambda x: x[5] - x[1] - x[1])
	clistpls = []
	clistmin = []
	for x in comp:
		if x[2] > x[5] - x[2]:
			clistpls.append(x)
		else:
			clistmin.append(x)
	clistpls.sort(key=lambda x: x[2] / x[5], reverse=True)
	clistmin.sort(key=lambda x: x[5] - x[2] - x[2])
	dlistpls = []
	dlistmin = []
	for x in comp:
		if x[3] > x[5] - x[3]:
			dlistpls.append(x)
		else:
			dlistmin.append(x)
	dlistpls.sort(key=lambda x: x[3] / x[5], reverse=True)
	dlistmin.sort(key=lambda x: x[5] - x[3] - x[3])
	elistpls = []
	elistmin = []
	for x in comp:
		if x[4] > x[5] - x[4]:
			elistpls.append(x)
		else:
			elistmin.append(x)
	elistpls.sort(key=lambda x: x[4] / x[5], reverse=True)
	elistmin.sort(key=lambda x: x[5] - x[4] - x[4])
	res = 0
	res = func(alistpls, alistmin, res, 0)
	res = func(blistpls, blistmin, res, 1)
	res = func(clistpls, clistmin, res, 2)
	res = func(dlistpls, dlistmin, res, 3)
	res = func(elistpls, elistmin, res, 4)
	print(res)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	sli = []
	ans = 0
	for i in range(n):
		s = input()
		sli.append(s)
	ba = 'abcde'
	for ke in ba:
		targetList = []
		for i in range(n):
			originS = sli[i]
			more = len(originS) - originS.count(ke) - originS.count(ke)
			targetList.append((originS, more))
		targetList = sorted(targetList, key=lambda t: t[1])
		ians = 0
		re = 0
		for ti in targetList:
			re += ti[1]
			if re < 0:
				ians += 1
			else:
				break
		if ians > ans:
			ans = ians
	print(ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	ss = []
	ss.clear()
	for i in range(n):
		ss.append(str(input()).strip())
	ans = 0
	for i in range(97, 123):
		x = str(chr(i))
		pts = []
		pts.clear()
		for j in range(n):
			pts.append(len(ss[j]) - 2 * ss[j].count(x))
		pts.sort()
		y = 0
		for j in range(n):
			y += pts[j]
			ans = max(ans, j)
			if y >= 0:
				break
		if y < 0:
			ans = max(ans, n)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from math import ceil, floor, sqrt, log2, gcd, pi
from heapq import heappush, heappop
from fractions import Fraction
from bisect import bisect_left, bisect
import sys
abc = 'abcdefghijklmnopqrstuvwxyz'
ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def insa(ca, l, a, a_):
	if ca != l:
		if ca >= l - ca:
			a.append((ca / (l - ca), ca, l - ca))
		else:
			a_.append((l - ca - ca, ca, l))
	else:
		a.append((float('inf'), ca, l - ca))

def insb(cb, l, b, b_):
	if cb != l:
		if cb >= l - cb:
			b.append((cb / (l - cb), cb, l - cb))
		else:
			b_.append((l - cb - cb, cb, l))
	else:
		b.append((float('inf'), cb, l - cb))

def insc(cc, l, c, c_):
	if cc != l:
		if cc >= l - cc:
			c.append((cc / (l - cc), cc, l - cc))
		else:
			c_.append((l - cc - cc, cc, l))
	else:
		c.append((float('inf'), cc, l - cc))

def insd(cd, l, d, d_):
	if cd != l:
		if cd >= l - cd:
			d.append((cd / (l - cd), cd, l - cd))
		else:
			d_.append((l - cd - cd, cd, l))
	else:
		d.append((float('inf'), cd, l - cd))

def inse(ce, l, e, e_):
	if ce != l:
		if ce >= l - ce:
			e.append((ce / (l - ce), ce, l - ce))
		else:
			e_.append((l - ce - ce, ce, l))
	else:
		e.append((float('inf'), ce, l - ce))
for _ in range(int(input())):
	n = int(input())
	arr = []
	a = []
	a_ = []
	b = []
	b_ = []
	c = []
	c_ = []
	d = []
	d_ = []
	e = []
	e_ = []
	for t in range(n):
		(ca, cb, cc, cd, ce) = (0, 0, 0, 0, 0)
		s = input()
		l = len(s)
		for i in s:
			if i == 'a':
				ca += 1
			elif i == 'b':
				cb += 1
			elif i == 'c':
				cc += 1
			elif i == 'd':
				cd += 1
			elif i == 'e':
				ce += 1
		insa(ca, l, a, a_)
		insb(cb, l, b, b_)
		insc(cc, l, c, c_)
		insd(cd, l, d, d_)
		inse(ce, l, e, e_)
	a.sort(reverse=True)
	b.sort(reverse=True)
	c.sort(reverse=True)
	d.sort(reverse=True)
	e.sort(reverse=True)
	a_.sort()
	b_.sort()
	c_.sort()
	d_.sort()
	e_.sort()
	maxi = 0
	na = 0
	no = 0
	num = 0
	for (i, j, k) in a:
		if na + j > no + k:
			na += j
			no += k
			num += 1
			maxi = max(maxi, num)
	for (i, j, k) in a_:
		if na + j > no + i + j:
			na += j
			no += i + j
			num += 1
			maxi = max(maxi, num)
	na = 0
	no = 0
	num = 0
	for (i, j, k) in b:
		if na + j > no + k:
			na += j
			no += k
			num += 1
			maxi = max(maxi, num)
	for (i, j, k) in b_:
		if na + j > no + i + j:
			na += j
			no += i + j
			num += 1
			maxi = max(maxi, num)
	na = 0
	no = 0
	num = 0
	for (i, j, k) in c:
		if na + j > no + k:
			na += j
			no += k
			num += 1
			maxi = max(maxi, num)
	for (i, j, k) in c_:
		if na + j > no + i + j:
			na += j
			no += i + j
			num += 1
			maxi = max(maxi, num)
	na = 0
	no = 0
	num = 0
	for (i, j, k) in d:
		if na + j > no + k:
			na += j
			no += k
			num += 1
			maxi = max(maxi, num)
	for (i, j, k) in d_:
		if na + j > no + i + j:
			na += j
			no += i + j
			num += 1
			maxi = max(maxi, num)
	na = 0
	no = 0
	num = 0
	for (i, j, k) in e:
		if na + j > no + k:
			na += j
			no += k
			num += 1
			maxi = max(maxi, num)
	for (i, j, k) in e_:
		if na + j > no + i + j:
			na += j
			no += i + j
			num += 1
			maxi = max(maxi, num)
	print(maxi)


from collections import Counter

def find_max(arr):
	arr = list(reversed(sorted(arr)))
	ans = 0
	for i in range(len(arr)):
		ans += arr[i]
		if ans <= 0:
			return i
	return len(arr)
t = int(input())
for _ in range(t):
	arr = [[], [], [], [], []]
	n = int(input())
	for i in range(n):
		s = input()
		x = len(s)
		c = Counter(s)
		arr[0].append(2 * c['a'] - x)
		arr[1].append(2 * c['b'] - x)
		arr[2].append(2 * c['c'] - x)
		arr[3].append(2 * c['d'] - x)
		arr[4].append(2 * c['e'] - x)
	print(max((find_max(a) for a in arr)))


T = int(input())
set_n = ('a', 'b', 'c', 'd', 'e')

def solve():
	n = int(input())
	words = [''] * n
	for i in range(n):
		words[i] = input()
	ans = 0
	for main_v in set_n:
		arr = sorted([2 * x.count(main_v) - len(x) for x in words], reverse=True)
		sum_n = 0
		c = 0
		for a in arr:
			if sum_n + a <= 0:
				break
			sum_n += a
			c += 1
		ans = max(ans, c)
	print(ans)
	return
for _ in range(T):
	solve()


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
from math import cos, sin
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def solve(a, v):
	ct = tot - 2 * v
	while a and ct >= 0:
		t1 = a.pop()
		ct -= t1
	return len(a)
for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	c = []
	d = []
	e = []
	a1 = b1 = c1 = d1 = e1 = 0
	for _ in range(n):
		ar = input()
		l = len(ar)
		mp = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
		for i in ar:
			mp[i] += 1
		a.append(l - 2 * mp['a'])
		b.append(l - 2 * mp['b'])
		c.append(l - 2 * mp['c'])
		d.append(l - 2 * mp['d'])
		e.append(l - 2 * mp['e'])
		a1 += mp['a']
		b1 += mp['b']
		c1 += mp['c']
		d1 += mp['d']
		e1 += mp['e']
	a.sort()
	b.sort()
	c.sort()
	d.sort()
	e.sort()
	ans = 0
	tot = a1 + b1 + c1 + d1 + e1
	ans = max(ans, solve(a, a1))
	ans = max(ans, solve(b, b1))
	ans = max(ans, solve(c, c1))
	ans = max(ans, solve(d, d1))
	ans = max(ans, solve(e, e1))
	print(ans)


from collections import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	r = []
	for i in range(n):
		r.append(st())
	ma = 0
	for i in range(5):
		char = chr(97 + i)
		tot = []
		cur_co = 0
		other = 0
		lenn = 0
		for j in range(n):
			x = r[j].count(char)
			z = len(r[j]) - x
			tot.append(x - z)
		tot.sort(reverse=True)
		so = 0
		for j in range(n):
			so += tot[j]
			lenn += 1
			if so <= 0:
				lenn -= 1
				break
		ma = max(ma, lenn)
	print(ma)


def count_letter(char, word):
	count = 0
	for c in word:
		if c == char:
			count += 1
	return 2 * count - len(word)

def solve():
	n = int(input())
	words = []
	for _ in range(n):
		word = input()
		words.append(word)
	max_count = 0
	for char in ['a', 'b', 'c', 'd', 'e']:
		temp = []
		for word in words:
			temp.append(count_letter(char, word))
		temp.sort(reverse=True)
		if temp[0] <= 0:
			continue
		count = 0
		local_max = 0
		for num in temp:
			local_max += num
			if local_max > 0:
				count += 1
			else:
				break
		max_count = max(max_count, count)
	print(max_count)
t = 1
t = int(input())
for i in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	array = [[] for i in range(5)]
	for i in range(n):
		s = input()
		length = s.__len__()
		arr = [0] * 5
		for j in range(length):
			x = ord(s[j]) - ord('a')
			for k in range(5):
				if k == x:
					arr[k] += 1
				else:
					arr[k] -= 1
		for j in range(5):
			array[j].append(arr[j])
	for i in range(5):
		array[i].sort()
	maxi = 0
	for i in range(5):
		summa = 0
		cnt = 0
		for j in range(n - 1, -1, -1):
			if summa + array[i][j] <= 0:
				break
			summa += array[i][j]
			cnt += 1
		maxi = max(maxi, cnt)
	print(maxi)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
n = l = 0

def check(tot):
	global l, n
	first = 0
	second = 0
	for i in range(n):
		first += l[i][tot]
		second += sum(l[i]) - l[i][tot]
	l.sort(key=lambda x: 2 * x[tot] - sum(x))
	temp = n
	ind = 0
	while first <= second and temp:
		first -= l[ind][tot]
		second -= sum(l[ind]) - l[ind][tot]
		ind += 1
		temp -= 1
	return temp
for _ in range(val()):
	n = val()
	l = [[0] * 5 for i in range(n)]
	for i in range(n):
		s = st()
		l[i][0] = s.count('a')
		l[i][1] = s.count('b')
		l[i][2] = s.count('c')
		l[i][3] = s.count('d')
		l[i][4] = s.count('e')
	ma = 0
	for i in range(5):
		ma = max(ma, check(i))
	print(ma)


from sys import stdin, stdout
input = stdin.readline

def f(a, ch):
	vals = []
	for i in a:
		x = 0
		for j in i:
			if j == ch:
				x += 1
		vals.append(2 * x - len(i))
	ans = 0
	p = 0
	for i in sorted(vals, reverse=True):
		p += i
		if p <= 0:
			break
		ans += 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		s = input().strip()
		a.append(s)
	m = 0
	for i in ['a', 'b', 'c', 'd', 'e']:
		m = max(m, f(a, i))
	print(m)


t = int(input())
while t:
	n = int(input())
	l = []
	for i in range(n):
		l.append(input())
	ans = 0
	la = []
	for i in range(n):
		ca = l[i].count('a')
		ln = len(l[i])
		la.append(ca - ln + ca)
	la.sort(reverse=True)
	na = 0
	suma = 0
	for i in la:
		suma += i
		if suma > 0:
			na += 1
		else:
			break
	ans = max(ans, na)
	la = []
	for i in range(n):
		ca = l[i].count('b')
		ln = len(l[i])
		la.append(ca - ln + ca)
	la.sort(reverse=True)
	na = 0
	suma = 0
	for i in la:
		suma += i
		if suma > 0:
			na += 1
		else:
			break
	ans = max(ans, na)
	la = []
	for i in range(n):
		ca = l[i].count('c')
		ln = len(l[i])
		la.append(ca - ln + ca)
	la.sort(reverse=True)
	na = 0
	suma = 0
	for i in la:
		suma += i
		if suma > 0:
			na += 1
		else:
			break
	ans = max(ans, na)
	la = []
	for i in range(n):
		ca = l[i].count('d')
		ln = len(l[i])
		la.append(ca - ln + ca)
	la.sort(reverse=True)
	na = 0
	suma = 0
	for i in la:
		suma += i
		if suma > 0:
			na += 1
		else:
			break
	ans = max(ans, na)
	la = []
	for i in range(n):
		ca = l[i].count('e')
		ln = len(l[i])
		la.append(ca - ln + ca)
	la.sort(reverse=True)
	na = 0
	suma = 0
	for i in la:
		suma += i
		if suma > 0:
			na += 1
		else:
			break
	ans = max(ans, na)
	print(ans)
	t -= 1