Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef has $N$ dishes, numbered $1$ through $N$. For each valid $i$, dish $i$ is described by a string $D_{i}$ containing only lowercase vowels, i.e. characters 'a', 'e', 'i', 'o', 'u'.

A *meal* consists of exactly two dishes. Preparing a meal from dishes $i$ and $j$ ($i \neq j$) means concatenating the strings $D_{i}$ and $D_{j}$ in an arbitrary order into a string $M$ describing the meal. Chef *likes* this meal if the string $M$ contains each lowercase vowel at least once.

Now, Chef is wondering - what is the total number of (unordered) pairs of dishes such that he likes the meal prepared from these dishes?

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains a single string $D_{i}$.

------  Output ------
For each test case, print a single line containing one integer - the number of ways to prepare a meal Chef likes.

------  Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ |D_{i}| ≤ 1,000$ for each valid $i$
the sum of all |D_{i}| over all test cases does not exceed $3 \cdot 10^{7}$

------  Subtasks ------
Subtask #1 (20 points):
$1 ≤ T ≤ 100$
$1 ≤ N ≤ 100$
the sum of all |D_{i}| over all test cases does not exceed $20000$

Subtask #2 (80 points): original constraints

----- Sample Input 1 ------ 
1

3

aaooaoaooa

uiieieiieieuuu

aeioooeeiiaiei
----- Sample Output 1 ------ 
2
----- explanation 1 ------ 
Example case 1: There are three possible meals:
- A meal prepared from dishes $1$ and $2$ (for example "aaooaoaooauiieieiieieuuu") contains all vowels.
- A meal prepared from dishes $1$ and $3$ (for example "aaooaoaooaaeioooeeiiaiei") does not contain 'u'.
- A meal prepared from dishes $2$ and $3$ (for example "uiieieiieieuuuaeioooeeiiaiei") contains all vowels.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: String algorithms

Data structures

Mathematics


Solutions:
def bit_dishes(str_dishes):
	dishes = [0] * 32
	(a, e, i, o, u) = (1, 1 << 1, 1 << 2, 1 << 3, 1 << 4)
	for str_dish in str_dishes:
		dish = 0
		for c in str_dish:
			if c == 'a':
				dish |= a
			elif c == 'e':
				dish |= e
			elif c == 'i':
				dish |= i
			elif c == 'o':
				dish |= o
			elif c == 'u':
				dish |= u
			if dish == 31:
				break
		dishes[dish] += 1
	return dishes

def count_good(dishes):
	res = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				res += dishes[i] * dishes[j]
	res += dishes[31] * (dishes[31] - 1) // 2
	return res
trials = int(input())
for _ in range(trials):
	n = int(input())
	dishes = [''] * n
	for i in range(n):
		dishes[i] = input()
	dishes = bit_dishes(dishes)
	print(count_good(dishes))


import itertools
power_set = [''.join(map(str, k)) for k in map(list, itertools.product([0, 1], repeat=5))]

def get_bitmask(S):
	indexes = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
	bitmask = [0] * 5
	for ch in S:
		bitmask[indexes[ch]] = 1
	return

def get_mask(S):
	indexes = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
	mask = 0
	for ch in S:
		mask += 2 ** indexes[ch]
	return mask

def find_union(x, y):
	res = ''
	for (p, q) in zip(x, y):
		res += str(int(p) or int(q))
	return res
for i in range(int(input())):
	N = int(input())
	di_set = []
	dp = [0] * 32
	for _ in range(N):
		mask = get_mask(set(input()))
		dp[mask] += 1
	likes_dishes = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				likes_dishes += dp[i] * dp[j]
	likes_dishes += dp[31] * (dp[31] - 1) // 2
	print(likes_dishes)


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

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

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

def ip():
	return input()

def make():
	d = {}
	d['a'] = 0
	d['e'] = 0
	d['i'] = 0
	d['o'] = 0
	d['u'] = 0
	return d
ar = [[''], ['u'], ['o'], ['o', 'u'], ['i'], ['i', 'u'], ['i', 'o'], ['i', 'o', 'u'], ['e'], ['e', 'u'], ['e', 'o'], ['e', 'o', 'u'], ['e', 'i'], ['e', 'i', 'u'], ['e', 'i', 'o'], ['e', 'i', 'o', 'u'], ['a'], ['a', 'u'], ['a', 'o'], ['a', 'o', 'u'], ['a', 'i'], ['a', 'i', 'u'], ['a', 'i', 'o'], ['a', 'i', 'o', 'u'], ['a', 'e'], ['a', 'e', 'u'], ['a', 'e', 'o'], ['a', 'e', 'o', 'u'], ['a', 'e', 'i'], ['a', 'e', 'i', 'u'], ['a', 'e', 'i', 'o'], ['a', 'e', 'i', 'o', 'u']]
for tastcas in range(int(input())):
	n = ii()
	c = [0] * 32
	ans = 0
	nn = n - 1
	for i in range(n):
		s = input()
		v = make()
		w = ''
		for i in s:
			v[i] = 1
		for (k, v) in sorted(v.items()):
			w += str(v)
		c[int(w, 2)] += 1
	for i in range(1, 31):
		for j in range(i + 1, 31):
			if len(set(ar[i] + ar[j])) == 5:
				ans += c[i] * c[j]
	tt = nn - c[-1]
	ans += nn * (nn + 1) // 2 - tt * (tt + 1) // 2
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	f = [0] * 32
	for j in range(n):
		s = set(input())
		m = 0
		for j in s:
			if j == 'a':
				m = m | 1 << 0
			elif j == 'e':
				m = m | 1 << 1
			elif j == 'i':
				m = m | 1 << 2
			elif j == 'o':
				m = m | 1 << 3
			else:
				m = m | 1 << 4
		f[m] += 1
	for k in range(1, 31):
		for z in range(k + 1, 32):
			if k | z == 31:
				c += f[k] * f[z]
	c += f[31] * (f[31] - 1) // 2
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	f = [0] * 32
	for _ in range(n):
		s = set(input())
		mask = 0
		for i in s:
			if i == 'a':
				mask = mask | 1 << 0
			elif i == 'e':
				mask = mask | 1 << 1
			elif i == 'i':
				mask = mask | 1 << 2
			elif i == 'o':
				mask = mask | 1 << 3
			else:
				mask = mask | 1 << 4
		f[mask] += 1
	for i in range(1, 31):
		for j in range(i + 1, 32):
			if i | j == 31:
				c += f[i] * f[j]
	c += f[31] * (f[31] - 1) // 2
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	bit = [0] * 32
	for i in range(n):
		s = set(input())
		mask = 0
		for i in s:
			if i == 'a':
				mask = mask | 1 << 0
			if i == 'e':
				mask = mask | 1 << 1
			if i == 'i':
				mask = mask | 1 << 2
			if i == 'o':
				mask = mask | 1 << 3
			if i == 'u':
				mask = mask | 1 << 4
		bit[mask] += 1
	count = 0
	for i in range(1, 31):
		for j in range(i + 1, 32):
			if i | j == 31:
				count += bit[i] * bit[j]
	count += bit[31] * (bit[31] - 1) // 2
	print(count)


for _ in range(int(input())):
	n = int(input())
	F = [0] * 32
	res = 0
	for i in range(n):
		s = set(input())
		mask = 0
		for ch in s:
			if ch == 'a':
				mask |= 1 << 0
			if ch == 'e':
				mask |= 1 << 1
			if ch == 'i':
				mask |= 1 << 2
			if ch == 'o':
				mask |= 1 << 3
			if ch == 'u':
				mask |= 1 << 4
		F[mask] += 1
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				res += F[i] * F[j]
	res += F[31] * (F[31] - 1) // 2
	print(res)


import collections
for _ in range(int(input())):
	n = int(input())
	dp = [0] * 32
	for _ in range(n):
		s = input()
		temp = 0
		for ch in s:
			if ch == 'a':
				temp = temp | 1 << 0
			elif ch == 'e':
				temp = temp | 1 << 1
			elif ch == 'i':
				temp = temp | 1 << 2
			elif ch == 'o':
				temp = temp | 1 << 3
			else:
				temp = temp | 1 << 4
		dp[temp] += 1
	ans = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += dp[i] * dp[j]
	ans += dp[31] * (dp[31] - 1) // 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	dp = [0] * 32
	for i in range(n):
		my_set = list(input().strip())
		my_set = set(my_set)
		mask = 0
		for j in my_set:
			if j == 'a':
				mask = mask | 1 << 0
			if j == 'e':
				mask = mask | 1 << 1
			if j == 'i':
				mask = mask | 1 << 2
			if j == 'o':
				mask = mask | 1 << 3
			if j == 'u':
				mask = mask | 1 << 4
		dp[mask] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans = ans + dp[i] * dp[j]
	ans = ans + dp[31] * (dp[31] - 1) // 2
	print(ans)


class Solution(object):

	def tastyMeal(self, dishes):
		freq = [0] * 32
		for d in range(len(dishes)):
			mask = 0
			dish = dishes[d]
			for ch in dish:
				if ch == 'a':
					mask = mask | 1 << 0
				if ch == 'e':
					mask = mask | 1 << 1
				if ch == 'i':
					mask = mask | 1 << 2
				if ch == 'o':
					mask = mask | 1 << 3
				if ch == 'u':
					mask = mask | 1 << 4
			freq[mask] = freq[mask] + 1
		tasty_dishes = 0
		for i in range(32):
			for j in range(i + 1, 32):
				if i | j == 31:
					tasty_dishes = tasty_dishes + freq[i] * freq[j]
		tasty_dishes = tasty_dishes + freq[31] * (freq[31] - 1) // 2
		return tasty_dishes
t = int(input())
for _ in range(t):
	dishes = []
	n = int(input())
	for i in range(n):
		dishes.append(input())
	sol = Solution()
	ans = sol.tastyMeal(dishes)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = []
	dp = [0] * 32
	for _ in range(n):
		string = input()
		temp = 0
		for ch in string:
			if ch == 'a':
				temp = temp | 1 << 0
			elif ch == 'e':
				temp = temp | 1 << 1
			elif ch == 'i':
				temp = temp | 1 << 2
			elif ch == 'o':
				temp = temp | 1 << 3
			else:
				temp = temp | 1 << 4
		dp[temp] += 1
	ans = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += dp[i] * dp[j]
	ans += dp[31] * (dp[31] - 1) // 2
	print(ans)


for _ in range(int(input())):
	N = int(input())
	F = [0] * 32
	for i in range(N):
		mask = 0
		s = input()
		for j in s:
			if j == 'a':
				mask = mask | 1 << 0
			elif j == 'e':
				mask = mask | 1 << 1
			elif j == 'i':
				mask = mask | 1 << 2
			elif j == 'o':
				mask = mask | 1 << 3
			else:
				mask = mask | 1 << 4
		F[mask] += 1
	res = 0
	for i in range(1, 32):
		if F[i] > 0:
			for j in range(i + 1, 32):
				if i | j == 31 and F[j] > 0:
					res = res + F[i] * F[j]
	res = res + F[31] * (F[31] - 1) // 2
	print(res)


t = int(input())
binrep = {'a': 16, 'e': 8, 'i': 4, 'o': 2, 'u': 1}

def convert(ch):
	return binrep[ch]
while t:
	n = int(input())
	binrepfreq = [0] * 32
	ans = 0
	for i in range(n):
		rep = sum(map(convert, set(list(input()))))
		binrepfreq[rep] += 1
	for i in range(1, 31):
		for j in range(i + 1, 32):
			if i | j == 31:
				pairscount = binrepfreq[i] * binrepfreq[j]
				ans += pairscount
	pair31 = (binrepfreq[31] * binrepfreq[31] - binrepfreq[31]) // 2
	ans += pair31
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = []
	f = [0] * 32
	l = len(f)
	for i in range(n):
		m = 0
		s = input()
		if 'a' in s:
			m = m | 1 << 0
		if 'e' in s:
			m = m | 1 << 1
		if 'i' in s:
			m = m | 1 << 2
		if 'o' in s:
			m = m | 1 << 3
		if 'u' in s:
			m = m | 1 << 4
		f[m] += 1
	c = 0
	for i in range(l + 1):
		for j in range(i + 1, l + 1):
			if i | j == 31:
				c += f[i] * f[j]
	d = f[31]
	d = d * (d - 1) // 2
	c += d
	print(c)


T = int(input())
for i in range(T):
	n = int(input())
	lst = [0] * (1 << 5)
	for j in range(n):
		ans = 0
		for k in input():
			if k == 'a':
				ans |= 1 << 0
			elif k == 'e':
				ans |= 1 << 1
			elif k == 'i':
				ans |= 1 << 2
			elif k == 'o':
				ans |= 1 << 3
			else:
				ans |= 1 << 4
		lst[ans] += 1
	ans = 0
	for j in range(1, 31):
		for k in range(j, 32):
			if j | k == 31:
				ans += lst[j] * lst[k]
	ans += lst[31] * (lst[31] - 1) // 2
	print(ans)


def solve(s):
	l = ['0'] * 5
	d = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
	for i in s:
		if i in 'aeiou' or i in 'AEIOU':
			l[d[i.lower()]] = '1'
	l.reverse()
	return ''.join(l)

def main():
	for _ in range(int(input())):
		n = int(input())
		k = 1 << 5
		l = [0] * k
		for i in range(n):
			s = input()
			a = solve(s)
			a = int(a, 2)
			l[a] += 1
		c = 0
		for i in range(k):
			for j in range(i + 1, k):
				if l[i] and l[j] and (i | j == k - 1):
					c += l[i] * l[j]
		c += l[31] * (l[31] - 1) // 2
		print(c)
main()


p = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
for _ in range(int(input())):
	n = int(input())
	l = []
	d = {i: 0 for i in range(0, 32)}
	for i in range(n):
		s = input()
		s = set(s)
		val = 0
		for i in s:
			val = val | 1 << p[i]
		d[val] += 1
	l = [i for i in d]
	n = len(l)
	ans = 0
	for i in range(n):
		for j in range(i, n):
			findor = l[i] | l[j]
			if findor == 31:
				if l[i] == l[j] == 31:
					ans = ans + d[31] * (d[31] - 1) // 2
				else:
					ans += d[l[i]] * d[l[j]]
	print(ans)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

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

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

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

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = inp()
	d = defaultdict(int)
	x = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
	for i in range(n):
		s = set(st())
		a = 0
		for j in s:
			a |= 1 << x[j]
		d[a] += 1
	ans = 0
	for i in range(32):
		for j in range(i, 32):
			if i | j == 31:
				if i == j == 31:
					ans += d[i] * (d[i] - 1) // 2
				else:
					ans += d[i] * d[j]
	pr(ans)
for _ in range(inp()):
	solve()


def evaluatestring(dp, string):
	mask = 0
	for s in string:
		if s == 'a':
			mask |= 1 << 0
		elif s == 'e':
			mask |= 1 << 1
		elif s == 'i':
			mask |= 1 << 2
		elif s == 'o':
			mask |= 1 << 3
		elif s == 'u':
			mask |= 1 << 4
	dp[mask] += 1
	return dp
testcase = int(input())
while testcase:
	dp = [0] * 32
	number = int(input())
	for _ in range(number):
		string = input().lower()
		dp = evaluatestring(dp, string)
	answer = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				answer += dp[i] * dp[j]
	answer += dp[31] * (dp[31] - 1) // 2
	print(answer)
	testcase -= 1


t = int(input())
for _ in range(t):
	dp = [0] * 32
	n = int(input())
	for _ in range(n):
		st = input()
		mask = 0
		for ch in st:
			if ch == 'a':
				mask = mask | 1 << 0
			elif ch == 'e':
				mask = mask | 1 << 1
			elif ch == 'i':
				mask = mask | 1 << 2
			elif ch == 'o':
				mask = mask | 1 << 3
			elif ch == 'u':
				mask = mask | 1 << 4
		dp[mask] += 1
	answer = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				answer += dp[i] * dp[j]
	answer += dp[31] * (dp[31] - 1) // 2
	print(answer)


for _ in range(int(input())):
	n = int(input())
	f = [0] * 32
	for x in range(n):
		s = input()
		t = 0
		for c in s:
			if c == 'a':
				t |= 1 << 0
			elif c == 'e':
				t |= 1 << 1
			elif c == 'i':
				t |= 1 << 2
			elif c == 'o':
				t |= 1 << 3
			elif c == 'u':
				t |= 1 << 4
		f[t] += 1
	ans = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += f[i] * f[j]
	ans += f[31] * (f[31] - 1) / 2
	print(int(ans))


def solve(d, n):
	f = [0 for i in range(32)]
	for string in d:
		m = 0
		for ch in string:
			m = m | 1 << dct[ch]
			if m == 31:
				break
		f[m] += 1
	res = 0
	for i in range(1, 31):
		for j in range(i + 1, 32):
			if i | j == 31:
				res += f[i] * f[j]
	res += f[31] * (f[31] - 1) // 2
	return res
dct = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
for _ in range(int(input())):
	n = int(input())
	d = []
	for k in range(n):
		di = input()
		d.append(di)
	print(solve(d, n))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		s = input()
		arr.append(set(s))
	bit = [0] * 32
	for i in range(n):
		mask = 0
		for j in arr[i]:
			if j == 'a':
				mask = mask | 1 << 0
			elif j == 'e':
				mask = mask | 1 << 1
			elif j == 'i':
				mask = mask | 1 << 2
			elif j == 'o':
				mask = mask | 1 << 3
			else:
				mask = mask | 1 << 4
		bit[mask] = bit[mask] + 1
	ans = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans = ans + bit[i] * bit[j]
	ans = ans + bit[31] * (bit[31] - 1) // 2
	print(ans)


def funct(li, n):
	f = [0 for i in range(32)]
	for i in range(len(li)):
		mask = 0
		for j in li[i]:
			if j == 'a':
				mask = mask | 1 << 0
			if j == 'e':
				mask = mask | 1 << 1
			if j == 'i':
				mask = mask | 1 << 2
			if j == 'o':
				mask = mask | 1 << 3
			if j == 'u':
				mask = mask | 1 << 4
		f[mask] += 1
	count = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				count += f[i] * f[j]
	count = count + f[31] * (f[31] - 1) // 2
	return count
t = int(input())
for i in range(t):
	n = int(input())
	li = []
	for i in range(n):
		s = input()
		li.append(set(s))
	print(funct(li, n))


for _ in range(int(input())):
	n = int(input())
	freq = [0] * 32
	for i in range(n):
		s = input()
		mask = 0
		for c in s:
			if c == 'a':
				mask = mask | 1 << 0
			elif c == 'e':
				mask = mask | 1 << 1
			elif c == 'i':
				mask = mask | 1 << 2
			elif c == 'o':
				mask = mask | 1 << 3
			elif c == 'u':
				mask = mask | 1 << 4
		freq[mask] += 1
	ans = 0
	for i in range(0, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += freq[i] * freq[j]
	ans += freq[31] * (freq[31] - 1) // 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	dp = dict()
	maps = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
	for __ in range(n):
		s = input()
		mask = 0
		for i in s:
			mask = mask | 1 << maps[i]
		if mask not in dp:
			dp[mask] = 1
		else:
			dp[mask] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				if i in dp and j in dp:
					ans += dp[i] * dp[j]
	if 31 in dp:
		ans += dp[31] * (dp[31] - 1) // 2
	print(ans)


D = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}

def chef(meals):
	freq = [0] * 32
	for s in meals:
		temp = 0
		for i in range(len(s)):
			temp |= 1 << D[s[i]]
		freq[temp] += 1
	res = 0
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				res += freq[i] * freq[j]
	res += freq[31] * (freq[31] - 1) // 2
	return res

def main():
	tc = int(input())
	for t in range(tc):
		n = int(input())
		meals = []
		for _ in range(n):
			meals.append(input())
		print(chef(meals))
main()


def solve(st):
	n = len(st)
	new_st = [0 for _ in range(n)]
	for i in range(n):
		for e in st[i]:
			if e == 'a':
				new_st[i] |= 1 << 0
			if e == 'e':
				new_st[i] |= 1 << 1
			if e == 'i':
				new_st[i] |= 1 << 2
			if e == 'o':
				new_st[i] |= 1 << 3
			if e == 'u':
				new_st[i] |= 1 << 4
	nn = 1 << 5
	ans = [0 for _ in range(nn)]
	for e in new_st:
		ans[e] += 1
	final_ans = 0
	for i in range(nn):
		for j in range(i + 1, nn):
			if i | j == 31:
				final_ans += ans[i] * ans[j]
	final_ans += ans[31] * (ans[31] - 1) // 2
	return final_ans
for _ in range(int(input())):
	n = int(input())
	st = [input() for _ in range(n)]
	print(solve(st))


from collections import defaultdict
for T in range(int(input())):
	n = int(input())
	count = {}
	count = defaultdict(lambda : 0, count)
	for i in range(n):
		dish = input()
		mask = 0
		for i in dish:
			if i == 'a':
				mask |= 1 << 0
			elif i == 'e':
				mask |= 1 << 1
			elif i == 'i':
				mask |= 1 << 2
			elif i == 'o':
				mask |= 1 << 3
			else:
				mask |= 1 << 4
		count[mask] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += count[i] * count[j]
	ans += count[31] * (count[31] - 1) // 2
	print(ans)


def solve():
	n = int(input())
	freq = dict()
	for i in range(32):
		freq[i] = 0
	for i in range(n):
		s = set(input())
		si = 0
		if 'a' in s:
			si += 1 << 0
		if 'e' in s:
			si += 1 << 1
		if 'i' in s:
			si += 1 << 2
		if 'o' in s:
			si += 1 << 3
		if 'u' in s:
			si += 1 << 4
		freq[si] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += freq[i] * freq[j]
	if freq[31]:
		ans += freq[31] * (freq[31] - 1) // 2
	print(ans)
for t in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	freq = [0] * 32
	for i in range(n):
		s = input()
		ans = 0
		s = list(set(s))
		for j in s:
			if j == 'a':
				ans = ans | 1
			if j == 'e':
				ans = ans | 2
			if j == 'i':
				ans = ans | 4
			if j == 'o':
				ans = ans | 8
			if j == 'u':
				ans = ans | 16
		freq[ans] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += freq[i] * freq[j]
	c = freq[31]
	ans += c * (c - 1) // 2
	print(ans)


t = int(input())
for _ in range(1, t + 1):
	n = int(input())
	fr = [0] * 32
	for k in range(n):
		s = set(input())
		mask = 0
		for i in s:
			if i == 'a':
				mask = mask | 1 << 0
			if i == 'e':
				mask = mask | 1 << 1
			if i == 'i':
				mask = mask | 1 << 2
			if i == 'o':
				mask = mask | 1 << 3
			if i == 'u':
				mask = mask | 1 << 4
		fr[mask] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += fr[i] * fr[j]
	ans += fr[31] * (fr[31] - 1) // 2
	print(ans)


from collections import defaultdict as df
from itertools import combinations as co

def mmap(s):
	sd = {'a': 1, 'e': 2, 'i': 4, 'o': 8, 'u': 16}
	v = 0
	for i in set(s):
		v |= sd[i]
	return v

def main():
	n = int(input())
	sd = df(int)
	for i in range(n):
		sd[mmap(input())] += 1
	k = list(sd.keys())
	ans = 0
	for (i, j) in co(k, 2):
		if i | j == 31:
			ans += sd[i] * sd[j]
	if 31 in k:
		xx = sd[31]
		ans += xx * (xx - 1) // 2
	print(ans)
for _ in range(int(input())):
	main()


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = [0] * 32
	l = []
	for i in range(n):
		s = stdin.readline()
		f = 0
		set_s = set(s)
		if 'u' in set_s:
			f = f | 1 << 0
		if 'o' in set_s:
			f = f | 1 << 1
		if 'i' in set_s:
			f = f | 1 << 2
		if 'e' in set_s:
			f = f | 1 << 3
		if 'a' in set_s:
			f = f | 1 << 4
		arr[f] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += arr[i] * arr[j]
	if arr[31] > 1:
		n = arr[31]
		ans += n * (n - 1) // 2
	print(ans)


def solve():
	n = int(input())
	freq_comb = [0] * 32
	for i in range(n):
		string = input()
		mask = 0
		for s in string:
			if s == 'a':
				mask = mask | 1 << 0
			elif s == 'e':
				mask = mask | 1 << 1
			elif s == 'i':
				mask = mask | 1 << 2
			elif s == 'o':
				mask = mask | 1 << 3
			else:
				mask = mask | 1 << 4
		freq_comb[mask] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += freq_comb[i] * freq_comb[j]
	ans += freq_comb[31] * (freq_comb[31] - 1) // 2
	return ans
t = int(input())
for _ in range(t):
	print(solve())


def maskit(x):
	j = 0
	for i in x:
		if i == 'a':
			j = j | 1 << 4
		elif i == 'e':
			j = j | 1 << 3
		elif i == 'i':
			j = j | 1 << 2
		elif i == 'o':
			j = j | 1 << 1
		elif i == 'u':
			j = j | 1 << 0
	return j
t = int(input())
for _ in range(t):
	n = int(input())
	dish = list()
	for i in range(n):
		x = input()
		dish.append(maskit(x))
	c = 0
	l = [0] * 32
	for i in range(n):
		l[dish[i]] += 1
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				c += l[i] * l[j]
	c += l[31] * (l[31] - 1) // 2
	print(c)


t = int(input())
for _ in range(t):
	f = [0] * 32
	ip = int(input())
	li = list()
	for i in range(ip):
		li.append(input())
	for i in li:
		mask = 0
		if 'a' in i:
			mask = mask | 1 << 0
		if 'e' in i:
			mask = mask | 1 << 1
		if 'i' in i:
			mask = mask | 1 << 2
		if 'o' in i:
			mask = mask | 1 << 3
		if 'u' in i:
			mask = mask | 1 << 4
		f[mask] += 1
	res = 0
	for i in range(len(f)):
		for j in range(i + 1, len(f)):
			if i | j == 31:
				res = res + f[i] * f[j]
	res = res + f[31] * (f[31] - 1) // 2
	print(res)


def func(s, dic):
	ch = 0
	for i in s:
		ch = ch | 1 << dic[i]
	return ch
from collections import defaultdict
from sys import stdin, stdout
t = int(input())
dic = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
for _ in range(t):
	n = int(stdin.readline())
	ideal = (1 << 5) - 1
	freq = defaultdict(int)
	for i in range(n):
		s = ''.join(list(set(input())))
		ch = func(s, dic)
		freq[ch] += 1
	l = list(freq.keys())
	l.sort()
	m = len(l)
	ans = 0
	for i in range(m):
		if l[i] == ideal:
			ch = freq[l[i]]
			ans += ch * (ch - 1) // 2
		for j in range(i + 1, m):
			if l[i] | l[j] == ideal:
				ans += freq[l[i]] * freq[l[j]]
	stdout.write(str(ans))
	print()


t = int(input())
while t:
	freq = [0] * 32
	n = int(input())
	for _ in range(n):
		s = input()
		mask = 0
		if 'a' in s:
			mask = mask | 1 << 0
		if 'e' in s:
			mask = mask | 1 << 1
		if 'i' in s:
			mask = mask | 1 << 2
		if 'o' in s:
			mask = mask | 1 << 3
		if 'u' in s:
			mask = mask | 1 << 4
		freq[mask] += 1
	res = 0
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				res += freq[i] * freq[j]
	res += freq[31] * (freq[31] - 1) // 2
	print(res)
	t -= 1


T = int(input())
for i in range(T):
	N = int(input())
	F = 1 << 5
	l = [0] * F
	l1 = []
	for j in range(N):
		x = input()
		l1.append(x)
	for j in range(len(l1)):
		mask = 0
		for k in l1[j]:
			if k == 'a':
				mask = mask | 1 << 0
			elif k == 'e':
				mask = mask | 1 << 1
			elif k == 'i':
				mask = mask | 1 << 2
			elif k == 'o':
				mask = mask | 1 << 3
			elif k == 'u':
				mask = mask | 1 << 4
		l[mask] += 1
	s = 0
	for j in range(32):
		for k in range(j + 1, 32):
			if j | k == 31:
				s = s + l[j] * l[k]
	if l[31] != 0:
		s = s + l[31] * (l[31] - 1) // 2
	print(s)


import sys
from math import sqrt, floor, factorial, gcd
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def is_prime(n):
	for i in range(2, int(sqrt(n))):
		if n % i == 0:
			return False
	return True

def solve():
	ans = ''
	dic = {'a': 1, 'e': 2, 'i': 4, 'o': 8, 'u': 16}
	for _ in range(int(inp())):
		total = 0
		combo = [0 for i in range(2 ** 5)]
		for i_ in range(int(inp())):
			tem = 0
			for i in inp().strip():
				if i in dic:
					tem |= dic[i]
			combo[tem] += 1
		for i in range(len(combo)):
			if combo[i]:
				for j in range(i + 1, len(combo)):
					if combo[j] and i | j == 31:
						total += combo[i] * combo[j]
		if combo[-1]:
			total += combo[-1] * (combo[-1] - 1) // 2
		ans += str(total) + '\n'
	print(ans)
solve()


shifts = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
for _ in range(int(input())):
	n = int(input())
	bitmasks = [0] * 2 ** 5
	for __ in range(n):
		s = input()
		b = 0
		for i in s:
			b = b | 1 << shifts[i]
		bitmasks[b] += 1
	res = 0
	for i in range(len(bitmasks)):
		for j in range(i + 1, len(bitmasks)):
			if i | j == 31:
				res += bitmasks[i] * bitmasks[j]
	res += bitmasks[-1] * (bitmasks[-1] - 1) // 2
	print(res)


N = 1 << 5
for t in range(int(input())):
	n = int(input())
	frq = [0 for i in range(N)]
	for i in range(n):
		d = list(input())
		index = 0
		for j in d:
			if j == 'a':
				index |= 1
			elif j == 'e':
				index |= 2
			elif j == 'i':
				index |= 4
			elif j == 'o':
				index |= 8
			elif j == 'u':
				index |= 16
		frq[index] += 1
	ans = 0
	for i in range(1, N):
		for j in range(i + 1, N):
			if i | j == 31:
				ans += frq[i] * frq[j]
	ans += frq[31] * (frq[31] - 1) // 2
	print(ans)


v = 'aeiou'
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	l = [0] * 32
	for i in range(n):
		s = set(input())
		d = dict()
		for j in v:
			d[j] = 0
		for j in s:
			if j in v:
				d[j] += 1
		val = d['a'] * 16 | d['e'] * 8 | d['i'] * 4 | d['o'] * 2 | d['u']
		l[val] += 1
	for i in range(1, 31):
		for j in range(i + 1, 32):
			if (l[i] and l[j]) and i | j == 31:
				c += l[i] * l[j]
	c += l[31] * (l[31] - 1) // 2
	print(c)


from collections import defaultdict

def Solve(Chance):
	L = len(Chance)
	Ans = 0
	for i in range(L):
		X = set(Chance[i])
		if X == {'a', 'e', 'i', 'o', 'u'}:
			Ans += Dict[Chance[i]] * (Dict[Chance[i]] - 1) // 2
		for j in range(i + 1, L):
			if X.union(set(Chance[j])) == {'a', 'e', 'i', 'o', 'u'}:
				Ans += Dict[Chance[i]] * Dict[Chance[j]]
	return Ans
for _ in range(int(input())):
	N = int(input())
	Dict = {}
	for i in range(N):
		I = ''.join(sorted(''.join(set(input()))))
		try:
			Dict[I] += 1
		except Exception:
			Dict[I] = 1
	Chance = list(Dict.keys())
	print(Solve(Chance))


import itertools
t = int(input())
for i in range(t):
	vowels = ['a', 'e', 'i', 'o', 'u']
	l = []
	n = int(input())
	for i in range(n):
		l.append(list(set(input())))
	combinations = []
	for i in range(len(vowels) + 1):
		combinations += list(itertools.combinations(vowels, i))
	for i in range(len(combinations)):
		combinations[i] = list(combinations[i])
	f = {}
	for i in combinations:
		a = ''.join(i)
		f[a] = 0
	for i in l:
		l2 = ''
		for j in range(len(i)):
			if i[j] in vowels:
				l2 += i[j]
		l2 = set(l2)
		l2 = list(l2)
		l2 = sorted(l2)
		l2 = ''.join(l2)
		f[l2] += 1
	sum1 = 0
	for i in f:
		if i != 'aeiou':
			sum1 += f[i]
	final = {}
	for i in f:
		if f[i] > 0:
			final[i] = f[i]
	f1 = list(final)
	ans = 0
	for i in range(len(f1)):
		for j in range(i + 1, len(f1)):
			if f1[i] != 'aeiou' and f1[j] != 'aeiou':
				k = f1[i] + f1[j]
				k = set(k)
				k = list(k)
				k = sorted(k)
				k = ''.join(k)
				if k == 'aeiou':
					ans += final[f1[i]] * final[f1[j]]
		if f1[i] == 'aeiou':
			ans += final[f1[i]] * sum1 + (final[f1[i]] - 1) * final[f1[i]] // 2
	print(ans)


t = int(input())
for k in range(t):
	l = [0] * 32
	n = int(input())
	for z in range(n):
		s1 = list(set(input()))
		num = 0
		for ch in s1:
			if ch == 'a':
				num = num + 10000
			elif ch == 'e':
				num = num + 1000
			elif ch == 'i':
				num = num + 100
			elif ch == 'o':
				num = num + 10
			elif ch == 'u':
				num = num + 1
		val = int(str(num), base=2)
		l[val] = l[val] + 1
	c = 0
	for i in range(1, 31):
		for j in range(i + 1, 32):
			if (l[i] and l[j]) and i | j == 31:
				c = c + l[i] * l[j]
	c = c + l[31] * (l[31] - 1) // 2
	print(c)


for _ in range(int(input())):
	n = int(input())
	l = []
	yt = (1 << 5) - 1
	d = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
	for _ in range(n):
		l.append(str(input()))
	v = {}
	for i in range(1, 32):
		v[i] = 0
	for i in range(n):
		s = set()
		m = 0
		for j in range(len(l[i])):
			s.add(d[l[i][j]])
		for x in s:
			m += 1 << x
		v[m] += 1
	ans = 0
	for i in range(1, 32):
		for j in range(1, 32):
			if i | j == yt:
				if i == j:
					ans += v[i] * (v[j] - 1)
				else:
					ans += v[i] * v[j]
	print(int(ans / 2))


from collections import defaultdict
for _ in range(int(input())):
	d = defaultdict(int)
	n = int(input())
	array = []
	length = 0
	for i in range(n):
		value = 0
		a = set(input())
		if 'a' in a:
			value |= 16
		if 'e' in a:
			value |= 8
		if 'i' in a:
			value |= 4
		if 'o' in a:
			value |= 2
		if 'u' in a:
			value |= 1
		if d[value] == 0:
			length += 1
			array.append(value)
		d[value] += 1
	ans = 0
	for i in range(length):
		for j in range(i, length):
			if array[i] | array[j] == 31:
				if array[i] != array[j]:
					ans += d[array[i]] * d[array[j]]
				else:
					ans += d[array[i]] * (d[array[j]] - 1) // 2
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		s = input()
		(a, b, c, d, e) = '0' * 5
		for j in s:
			if j == 'a':
				a = '1'
			if j == 'e':
				b = '1'
			if j == 'i':
				c = '1'
			if j == 'o':
				d = '1'
			if j == 'u':
				e = '1'
		x = a + b + c + d + e
		l.append(int(x, 2))
	d = {}
	ans = 0
	for i in range(32):
		d[i] = 0
	for i in l:
		d[i] += 1
	for i in range(31):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += d[i] * d[j]
	ans += d[31] * (d[31] - 1) // 2
	print(ans)


from collections import defaultdict
t = int(input())
while t:
	n = int(input())
	l = []
	final_dict = defaultdict(int)
	for i in range(n):
		temp = ''
		s = input()
		temp += '1' if 'a' in s else '0'
		temp += '1' if 'e' in s else '0'
		temp += '1' if 'i' in s else '0'
		temp += '1' if 'o' in s else '0'
		temp += '1' if 'u' in s else '0'
		final_dict[temp] += 1
	final_dict_keys = list(final_dict.keys())
	final_ans = 0
	if final_dict['11111'] > 1:
		final_ans += (final_dict['11111'] - 1) * final_dict['11111'] // 2
	for (ind, i) in enumerate(final_dict_keys):
		for j in final_dict_keys[ind + 1:]:
			if int(i, 2) | int(j, 2) == 31:
				final_ans += final_dict[i] * final_dict[j]
	print(final_ans)
	t -= 1


t = int(input())
for l1 in range(t):
	ans = 0
	cmb = {}
	n = int(input())
	for l2 in range(n):
		inp = str(input())
		vwl = set(inp)
		vwl = ''.join(list(sorted(vwl)))
		if vwl in cmb:
			cmb[vwl] += 1
		else:
			cmb[vwl] = 1
	for i in cmb.keys():
		for j in cmb.keys():
			if i != j:
				if len(set(i + j)) == 5:
					ans += cmb[i] * cmb[j]
	if 'aeiou' in cmb:
		ans += cmb['aeiou'] * (cmb['aeiou'] - 1)
	print(int(ans / 2))


for _ in range(int(input())):
	n = int(input())
	count = 0
	a1 = [0] * 32
	for i in range(n):
		t = [0] * 5
		s = set(input())
		for j in s:
			if j == 'a':
				t[0] = 1
			elif j == 'e':
				t[1] = 1
			elif j == 'i':
				t[2] = 1
			elif j == 'o':
				t[3] = 1
			elif j == 'u':
				t[4] = 1
		value = t[0] * 16 + t[1] * 8 + t[2] * 4 + t[3] * 2 + t[4] * 1
		a1[value] += 1
	for i in range(31):
		for j in range(i, 32):
			if i | j == 31:
				count += a1[i] * a1[j]
	x = a1[31]
	count += int(x * (x - 1) / 2)
	print(count)


R = lambda : map(int, input().split())

def shrink(string):
	return ''.join(sorted(list(set(string))))

def has_all_vowels(str1, str2):
	return set(str1 + str2) == {'a', 'e', 'i', 'o', 'u'}
for i in range(int(input())):
	n = int(input())
	map = {}
	for i in range(n):
		string = input()
		if shrink(string) in map:
			map[shrink(string)] += 1
		else:
			map[shrink(string)] = 1
	ans = 0
	for i in map:
		for j in map:
			if i != j and has_all_vowels(i, j):
				ans += map[i] * map[j]
	ans //= 2
	if 'aeiou' in map:
		ans += map['aeiou'] * (map['aeiou'] - 1) // 2
	print(ans)


from collections import defaultdict as dd

def complement(n):
	return 2 * 3 * 5 * 7 * 11 // n
for _ in range(int(input())):
	n = int(input())
	d = dd(int)
	ans = 0
	for i in range(n):
		s = input()
		s = str(sorted(set(s)))
		k = 1
		if 'a' in s:
			k *= 2
		if 'e' in s:
			k *= 3
		if 'i' in s:
			k *= 5
		if 'o' in s:
			k *= 7
		if 'u' in s:
			k *= 11
		d[k] += 1
	k = sorted(d.keys())
	for i in range(len(k)):
		c = complement(k[i])
		for j in range(i + 1, len(k)):
			if k[j] % c == 0:
				ans += d[k[i]] * d[k[j]]
		if k[i] == 2 * 3 * 5 * 7 * 11:
			ans += d[k[i]] * (d[k[i]] - 1) // 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = [0] * 32
	d = {'a': 1, 'e': 2, 'i': 4, 'o': 8, 'u': 16}
	for i in range(n):
		s = list(set(list(input())))
		m = 0
		for j in s:
			m |= d[j]
		l[m] += 1
	ans = l[31] * (l[31] - 1) // 2
	for i in range(1, 32):
		for j in range(i + 1, 32):
			if i | j == 31:
				ans += l[i] * l[j]
	print(ans)


dict = {'a': 0, 'e': 1, 'i': 2, 'o': 3, 'u': 4}
for _ in range(int(input())):
	N = int(input())
	strs = []
	arr = []
	for i in range(N):
		strs.append(str(input()))
	for s in strs:
		temp = [0] * 5
		for i in s:
			temp[dict[i]] = 1
		arr.append(temp)
	br = []
	for a in arr:
		s = [str(i) for i in a]
		res = str(''.join(s))
		br.append(res)
	s_dict = {}
	for a in br:
		if a in s_dict:
			s_dict[a] += 1
		else:
			s_dict[a] = 1
	f = []
	for s in s_dict:
		f.append(s)
		f.append(s_dict[s])
	(key, value) = (f[::2], f[1::2])
	pairs = 0
	if '11111' in s_dict:
		pairs = int(s_dict['11111'] * (s_dict['11111'] - 1) / 2)
	for i in range(len(key)):
		for j in range(i + 1, len(key)):
			flag = 1
			for k in range(5):
				if key[i][k] == '0' and key[j][k] == '0':
					flag = 0
			if flag == 1:
				pairs += value[i] * value[j]
	print(pairs)


def show(t):
	for _ in range(t):
		a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
		n = int(input())
		count = 0
		count_num = 0
		for lonavla in range(n):
			str1 = set(input())
			res = 0
			if 'a' in str1:
				res = res | 16
			if 'e' in str1:
				res = res | 8
			if 'i' in str1:
				res = res | 4
			if 'o' in str1:
				res = res | 2
			if 'u' in str1:
				res = res | 1
			a[res] += 1
		for i in range(31):
			for j in range(i + 1, 32):
				if i | j >= 31:
					count = count + a[i] * a[j]
		if a[31] > 0:
			count = count + a[31] * (a[31] - 1) // 2
		print(count)
show(int(input()))


d = {'a': 1, 'e': 2, 'i': 4, 'o': 8, 'u': 16}
for ii in range(int(input())):
	n = int(input())
	dd = {}
	for i in range(n):
		s = set(input())
		k = 0
		for j in s:
			k += d[j]
		if k in dd:
			dd[k] += 1
		else:
			dd[k] = 1
	c = 0
	for i in dd:
		for j in dd:
			if i | j == 31:
				if i == j:
					c += dd[i] * (dd[j] - 1)
				else:
					c += dd[i] * dd[j]
	print(c // 2)


for xxx in range(int(input())):
	n = int(input())
	desc = list()
	count = 0
	full = 'aeiou'
	table = dict()
	for _ in range(n):
		desc.append(''.join(sorted(''.join(set(input())))))
	desc.sort(key=lambda x: len(x))
	for d in desc:
		if d in table.keys():
			table[d] += 1
		else:
			table[d] = 1
	keys = list(table.keys())
	if desc[-1] == full:
		count += sum(range(1, table[full]))
	for (index, i) in enumerate(keys):
		for j in keys[index + 1:]:
			s = ''.join(sorted(''.join(set(i + j))))
			if s == full:
				count += table[i] * table[j]
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = [0] * 32
	for _ in range(n):
		word = set(input())
		mask = 0
		for i in word:
			if i == 'a':
				mask |= 1
			if i == 'e':
				mask |= 2
			if i == 'i':
				mask |= 4
			if i == 'o':
				mask |= 8
			if i == 'u':
				mask |= 16
		ans[mask] += 1
	count = ans[31] * (ans[31] - 1) // 2
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				count += ans[i] * ans[j]
	print(count)


t = int(input())
while t:
	n = int(input())
	d = []
	mask = [0] * 32
	for i in range(n):
		d.append(input())
		m = 0
		if 'a' in d[i]:
			m += 1
		if 'e' in d[i]:
			m += 2
		if 'i' in d[i]:
			m += 4
		if 'o' in d[i]:
			m += 8
		if 'u' in d[i]:
			m += 16
		mask[m] += 1
	mycount = mask[31] * (mask[31] - 1) // 2
	for i in range(32):
		for j in range(i + 1, 32):
			if i | j == 31:
				mycount += mask[i] * mask[j]
	print(mycount)
	t -= 1


def fun():
	test = int(input())
	for t in range(test):
		n = int(input())
		d = dict()
		arr = set()
		for _ in range(n):
			s1 = set(input().strip())
			vowels = ['a', 'e', 'i', 'o', 'u']
			val = 0
			for i in range(5):
				if vowels[i] in s1:
					val += 1 << i
			d[val] = d.get(val, 0) + 1
			arr.add(val)
		ans = 0
		m = len(arr)
		arr = list(arr)
		for i in range(m):
			for j in range(i + 1, m):
				if arr[i] | arr[j] == 31:
					ans += d[arr[i]] * d[arr[j]]
		x = d.get(31, 0)
		ans += x * (x - 1) // 2
		print(ans)
fun()


t = int(input())
while t:
	n = int(input())
	arr = [0] * 32
	for i in range(n):
		tmp = input()
		mask = 0
		for j in tmp:
			if 'a' is j:
				mask |= 16
				continue
			if 'e' is j:
				mask |= 8
				continue
			if 'i' is j:
				mask |= 4
				continue
			if 'o' is j:
				mask |= 2
				continue
			if 'u' is j:
				mask |= 1
		arr[mask] += 1
	mycount = arr[31] * (arr[31] - 1) // 2
	for i in range(32):
		for j in range(i + 1, 32):
			mycount += (0, arr[i] * arr[j])[i | j == 31]
	print(mycount)
	t -= 1


def decimal(bin_arr):
	return 2 * 2 * 2 * 2 * bin_arr['a'] + 2 * 2 * 2 * bin_arr['e'] + 2 * 2 * bin_arr['i'] + 2 * bin_arr['o'] + bin_arr['u']
T = int(input())
for i in range(T):
	count = 0
	arr = [0] * 32
	N = int(input())
	list_D = []
	for x in range(N):
		vowel_num = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0}
		for i in input():
			vowel_num[i] = 1
		list_D.append(vowel_num)
		arr[decimal(list_D[x])] += 1
	count = arr[31] * (arr[31] - 1) // 2
	for j in range(32):
		for k in range(j + 1, 32):
			if j | k == 31:
				count += arr[j] * arr[k]
	print(count)


t = int(input())
while t:
	n = int(input())
	lis = []
	s = ''
	a = [0] * n
	e = [0] * n
	i = [0] * n
	o = [0] * n
	u = [0] * n
	bt = [0] * n
	fr = [0] * 32
	for x in range(n):
		s = input()
		l = len(s)
		for j in s:
			if j == 'a':
				a[x] = 1
			elif j == 'e':
				e[x] = 1
			elif j == 'i':
				i[x] = 1
			elif j == 'o':
				o[x] = 1
			elif j == 'u':
				u[x] = 1
		bt[x] = a[x] * 16 + e[x] * 8 + i[x] * 4 + o[x] * 2 + u[x]
		fr[bt[x]] = fr[bt[x]] + 1
	c = 0
	for l in range(31):
		for g in range(l + 1, 32):
			if (fr[l] != 0 and fr[g] != 0) and l | g == 31:
				c = c + fr[l] * fr[g]
	b = fr[31]
	c = c + b * (b - 1) // 2
	print(c)
	t = t - 1


from collections import Counter

def binomialCoeff(n, k):
	C = [0 for i in range(k + 1)]
	C[0] = 1
	for i in range(1, n + 1):
		j = min(i, k)
		while j > 0:
			C[j] = C[j] + C[j - 1]
			j -= 1
	return C[k]
for _ in range(int(input())):
	n = int(input())
	a = [None] * n
	for i in range(n):
		a[i] = ''.join(sorted(list(set(list(input())))))
	y = dict(Counter(a))
	d = list(set(a))
	c = 0
	for i in range(len(d) - 1):
		for j in range(i + 1, len(d)):
			k = d[i][:] + d[j][:]
			k = list(set(list(k)))
			if len(k) == 5:
				c += y[d[i]] * y[d[j]]
	for i in range(len(d)):
		if len(d[i]) == 5:
			c += binomialCoeff(y[d[i]], 2)
	print(c)


T = int(input())
for _ in range(T):
	N = int(input())
	l = []
	a = [0 for i in range(32)]
	for i in range(N):
		s = input()
		x = 0
		a1 = 0
		a2 = 0
		a3 = 0
		a4 = 0
		a5 = 0
		if 'a' in s:
			a1 = 1
		if 'e' in s:
			a2 = 2
		if 'i' in s:
			a3 = 4
		if 'o' in s:
			a4 = 8
		if 'u' in s:
			a5 = 16
		x = a1 + a2 + a3 + a4 + a5
		a[x] += 1
	c = 0
	for k in range(1, 31):
		for l in range(k + 1, 32):
			if k | l == 31 and a[k] != 0 and (a[l] != 0):
				c += a[k] * a[l]
	c = c + a[31] * (a[31] - 1) // 2
	print(c)


t = int(input())
di = {'a': 16, 'e': 8, 'i': 4, 'o': 2, 'u': 1}
for i in range(t):
	n = int(input())
	d = {}
	for j in range(n):
		te = set(input())
		l = 0
		for k in te:
			l = l + di[k]
		if l in d:
			d[l] = d[l] + 1
		else:
			d[l] = 1
	li = list(d.keys())
	li.sort(reverse=True)
	count = 0
	if li[0] == 31:
		count = sum(range(1, d[31]))
	for j in range(len(li)):
		for k in range(j + 1, len(li)):
			if li[j] | li[k] == 31:
				count = count + d[li[j]] * d[li[k]]
	print(count)


from sys import stdin

class pair(object):

	def __init__(self, s1, s2):
		self.s1 = s1
		self.s2 = s2

def possible(s1, s2):
	s = set()
	for itms in s1:
		s.add(itms)
	for items in s2:
		s.add(items)
	if len(s) is 5:
		return True
	else:
		return False
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	m = dict()
	for _ in range(n):
		s = stdin.readline().rstrip()
		se = set()
		for items in s:
			se.add(items)
		se = sorted(se)
		see = ''
		for items in se:
			see += items
		if see not in m:
			m.update({see: 1})
		else:
			c = m.get(see)
			c = c + 1
			m.update({see: c})
	lis = list()
	for (k, v) in m.items():
		lis.append(pair(k, v))
	ans = 0
	for i in range(len(lis)):
		if len(lis[i].s1) is 5:
			continue
		for j in range(i + 1, len(lis)):
			if len(lis[j].s1) is 5:
				continue
			if possible(lis[i].s1, lis[j].s1) is True:
				ans = ans + lis[i].s2 * lis[j].s2
	add = 0
	ok = 'aeiou' in m.keys()
	if ok is True:
		add = add + m.get('aeiou') * (m.get('aeiou') - 1) / 2
		mew = m.get('aeiou')
		var = n - mew
		add = add + var * m.get('aeiou')
	print(int(ans + add))


t = int(input())
while t:
	n = int(input())
	d = []
	mymap = {}
	for i in range(n):
		d.append(input())
		x = 0
		if 'a' in d[i]:
			x += 16
		if 'e' in d[i]:
			x += 8
		if 'i' in d[i]:
			x += 4
		if 'o' in d[i]:
			x += 2
		if 'u' in d[i]:
			x += 1
		mymap.setdefault(x, 0)
		mymap[x] += 1
	mymap.setdefault(31, 0)
	mycount = int(mymap[31] * (mymap[31] - 1) // 2)
	for i in range(32):
		for j in range(i + 1, 32):
			mymap.setdefault(i, 0)
			mymap.setdefault(j, 0)
			if i | j == 31:
				mycount += mymap[i] * mymap[j]
	print(mycount)
	t -= 1


for _ in range(int(input())):
	arr = [0] * 32
	for _ in range(int(input())):
		val = 0
		list1 = list(set(input()))
		for i in range(len(list1)):
			if list1[i] == 'a':
				val += 10000
			elif list1[i] == 'e':
				val += 1000
			elif list1[i] == 'i':
				val += 100
			elif list1[i] == 'o':
				val += 10
			elif list1[i] == 'u':
				val += 1
		val = int(str(val), base=2)
		arr[val] += 1
	m = 0
	for i in range(1, 31):
		for j in range(i + 1, 32):
			if (arr[i] and arr[j]) and i | j == 31:
				m += arr[i] * arr[j]
	m += arr[31] * (arr[31] - 1) // 2
	print(m)