You are given a string S constisting of uppercase Latin letters. Is it possible to reorder the characters in this string to get a string with prefix "LTIME" and suffix "EMITL"?
We remind you that a prefix of a string is any substring which contains its first character, while a suffix of a string is substring containing its last character.

-----Input-----
The first line contains a single integer T, denoting the number of testcases. The descriptions of T test cases follow.
The first and only line of the test case description has one non-empty string S consisting of uppercase Latin letters only.

-----Output-----
For each testcase output a single line containing the string "YES" (without quotes) if it's possible to reorder the characters to get the required prefix and suffix, or "NO" (without quotes) otherwise.

-----Constraints-----
- Subtask 1 (23 points) : 1 ≤ T ≤ 100, 1 ≤ |S| ≤ 9
- Subtask 2 (77 points) : 1 ≤ T ≤ 1000, 1 ≤ |S| ≤ 100

-----Example-----
Input:3
LTIMEAZAZAITLME
LLLTTTIIIMMMEEEAHA
LTIMEM

Output:YES
YES
NO

-----Explanation-----
Test case 1: we can permute the last 5 letters and get LTIMEAZAZAEMITL
Test case 2: we have 3 copies of each of the letters 'L', 'T', 'I', 'M', 'E' so we can leave 5 of them in the beginning and move 5 of them to the end.
Test case 3: we have only one letter 'L' so we can't make necessary prefix and suffix at the same time.

Difficulty: MEDIUM

Solutions:
T = int(input())
for t in range(T):
	S = input()
	letter_count = {'L': 0, 'T': 0, 'I': 0, 'M': 0, 'E': 0}
	for c in S:
		if c in letter_count:
			letter_count[c] += 1
	lc_list = [letter_count['L'], letter_count['T'], letter_count['I'], letter_count['M'], letter_count['E']]
	print('YES') if all((count >= 2 for count in lc_list)) or lc_list == [2, 2, 2, 2, 1] else print('NO')


for i in range(int(input())):
	s = input()
	e = s.count('E')
	m = s.count('M')
	i = s.count('I')
	t = s.count('T')
	l = s.count('L')
	if e >= 1 and m >= 2 and (i >= 2) and (t >= 2) and (l >= 2) and (len(s) == 9):
		print('YES')
	elif e >= 2 and m >= 2 and (i >= 2) and (t >= 2) and (l >= 2) and (len(s) > 9):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = list(input())
	if s.count('L') >= 2 and s.count('T') >= 2 and (s.count('I') >= 2) and (s.count('M') >= 2) and (s.count('E') >= 2):
		print('YES')
		continue
	s.sort()
	if s == ['E', 'I', 'I', 'L', 'L', 'M', 'M', 'T', 'T']:
		print('YES')
	else:
		print('NO')


tt = int(input())
while tt > 0:
	tt = tt - 1
	s = input()
	l = 2
	t = 2
	i = 2
	m = 2
	if len(s) == 9:
		e = 1
	else:
		e = 2
	for c in s:
		if c == 'L':
			l = l - 1
		elif c == 'T':
			t = t - 1
		elif c == 'I':
			i = i - 1
		elif c == 'M':
			m = m - 1
		elif c == 'E':
			e = e - 1
		else:
			pass
	if l <= 0 and t <= 0 and (i <= 0) and (m <= 0) and (e <= 0):
		print('YES')
	else:
		print('NO')


for __ in range(int(input())):
	s = input()
	l = len(s)
	a = []
	for i in range(l):
		t = s[i]
		a.append(t)
	c1 = a.count('L')
	c2 = a.count('I')
	c3 = a.count('T')
	c4 = a.count('M')
	c5 = a.count('E')
	if c1 > 1 and c2 > 1 and (c3 > 1) and (c4 > 1) and (c5 > 1) or (l == 5 and c1 == 1 and (c2 == 1) and (c3 == 1) and (c4 == 1) and (c5 == 1)) or (c1 == 2 and c2 == 2 and (c3 == 2) and (c4 == 2) and (c5 == 1 or c5 == 2)):
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	S = input().split()
	l = list(list(S)[0])
	if l.count('L') >= 2 and l.count('T') >= 2 and (l.count('I') >= 2) and (l.count('M') >= 2) and (l.count('E') >= 1) and (l.count('A') == 0) and (l.count('B') == 0) and (l.count('C') == 0) and (l.count('D') == 0) and (l.count('F') == 0) and (l.count('G') == 0) and (l.count('H') == 0) and (l.count('J') == 0) and (l.count('K') == 0) and (l.count('N') == 0) and (l.count('O') == 0) and (l.count('P') == 0) and (l.count('Q') == 0) and (l.count('R') == 0) and (l.count('S') == 0) and (l.count('U') == 0) and (l.count('V') == 0) and (l.count('W') == 0) and (l.count('X') == 0) and (l.count('Y') == 0) and (l.count('Z') == 0):
		print('YES')
	elif l.count('L') >= 2 and l.count('T') >= 2 and (l.count('I') >= 2) and (l.count('M') >= 2) and (l.count('E') >= 2):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	x = str(input())
	if x.count('L') >= 2 and x.count('T') >= 2 and (x.count('I') >= 2) and (x.count('M') >= 2):
		if len(x) >= 10:
			if x.count('E') >= 2:
				print('YES')
			else:
				print('NO')
		elif x.count('E') >= 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	(l, t, I, m, e) = (0, 0, 0, 0, 0)
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'T':
			t += 1
		elif i == 'I':
			I += 1
		elif i == 'M':
			m += 1
		elif i == 'E':
			e += 1
	if l > 1 and t > 1 and (I > 1) and (m > 1) and (e > 1 or (e == 1 and len(s) == 9)):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	i = input()
	reqL = 0
	reqT = 0
	reqI = 0
	reqM = 0
	reqE = 0
	for val in i:
		if val == 'L':
			reqL += 1
		elif val == 'T':
			reqT += 1
		elif val == 'I':
			reqI += 1
		elif val == 'M':
			reqM += 1
		elif val == 'E':
			reqE += 1
	if min(reqL, reqM, reqT, reqI) > 1 and (reqE > 1 or len(i) == 9):
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	s = input()
	c = Counter(s)
	if c['L'] >= 2 and c['T'] >= 2 and (c['I'] >= 2) and (c['M'] >= 2):
		if len(s) == 9:
			if c['E'] >= 1:
				print('YES')
			else:
				print('NO')
		elif len(s) > 9:
			if c['E'] >= 2:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	s = [x for x in input().strip()]
	t = 2
	if len(s) == 9:
		t = 1
	if s.count('L') >= 2 and s.count('T') >= 2 and (s.count('I') >= 2) and (s.count('M') >= 2) and (s.count('E') >= t):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	hash = {}
	s = input()
	seti = {'L', 'T', 'I', 'M', 'E'}
	for i in s:
		try:
			hash[i]
		except:
			hash[i] = 1
		else:
			hash[i] += 1
	l = []
	flag = 0
	for i in hash.keys():
		if i in seti:
			if hash[i] >= 2:
				l.append(i)
				continue
			else:
				flag = 1
				break
	if len(l) == 5 and flag == 0:
		print('YES')
	elif len(s) == 9 and sorted(list(set(s))) == sorted(list(seti)):
		if hash['L'] == 2 and hash['T'] == 2 and (hash['I'] == 2) and (hash['M'] == 2) and (hash['E'] == 1):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for t in range(int(input())):
	s = input()
	n = len(s)
	if n < 9:
		print('NO')
	elif n == 9:
		if s.count('L') >= 2 and s.count('T') >= 2 and (s.count('I') >= 2) and (s.count('M') >= 2) and (s.count('E') >= 1):
			print('YES')
		else:
			print('NO')
	elif s.count('L') >= 2 and s.count('T') >= 2 and (s.count('I') >= 2) and (s.count('M') >= 2) and (s.count('E') >= 2):
		print('YES')
	else:
		print('NO')


from collections import Counter
T = int(input())
for _ in range(T):
	s = input()
	ct = Counter(s)
	if len(s) == 9:
		print('YES' if ct['E'] >= 1 and all((ct[c] >= 2 for c in 'LTIM')) else 'NO')
		continue
	print('YES' if len(s) >= 10 and all((ct[c] >= 2 for c in 'LTIME')) else 'NO')


for _ in range(int(input())):
	n = input()
	if n.count('L') >= 2 and n.count('T') >= 2 and (n.count('I') >= 2) and (n.count('M') >= 2) and (n.count('E') >= 2) or (len(n) == 9 and n.count('L') >= 2 and (n.count('T') >= 2) and (n.count('I') >= 2) and (n.count('M') >= 2) and (n.count('E') >= 0)):
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from math import ceil
import numpy as np
from numpy.linalg import matrix_power

def solve():
	mod = 10 ** 9 + 7
	for _ in range(int(input())):
		s = input().strip()
		n = len(s)
		(L, T, I, M, E) = (0, 0, 0, 0, 0)
		for i in range(n):
			if s[i] == 'L':
				L += 1
			elif s[i] == 'T':
				T += 1
			elif s[i] == 'I':
				I += 1
			elif s[i] == 'M':
				M += 1
			elif s[i] == 'E':
				E += 1
		if L > 1 and T > 1 and (I > 1) and (M > 1) and (E > 1) or (n == 5 and L == 1 and (T == 1) and (I == 1) and (M == 1) and (E == 1)) or (L == 2 and T == 2 and (I == 2) and (M == 2) and (E == 1 or E == 2)):
			print('YES')
		else:
			print('NO')
solve()


T = int(input())
for t in range(T):
	S = input()
	letter_count = {'L': 0, 'T': 0, 'I': 0, 'M': 0, 'E': 0}
	for c in S:
		if c in letter_count:
			letter_count[c] += 1
	letter_count_list = list(letter_count.values())
	if letter_count['L'] >= 2 and letter_count['T'] >= 2 and (letter_count['I'] >= 2) and (letter_count['M'] >= 2) and (letter_count['E'] >= 2):
		print('YES')
	elif letter_count['L'] == 2 and letter_count['T'] == 2 and (letter_count['I'] == 2) and (letter_count['M'] == 2) and (letter_count['E'] == 1):
		print('YES')
	else:
		print('NO')


import math
t = int(input())
while t > 0:
	s = input()
	s1 = list(s)
	yes = 0
	if s1.count('L') >= 2:
		yes = yes + 1
	if s1.count('T') >= 2:
		yes = yes + 1
	if s1.count('I') >= 2:
		yes = yes + 1
	if s1.count('M') >= 2:
		yes = yes + 1
	if s1.count('E') >= 2:
		yes = yes + 1
	if yes == 5:
		print('YES')
	elif len(s1) == 9:
		if yes == 4 and s1.count('E') == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	t = t - 1


from collections import Counter
t = int(input())
while t:
	s = input()
	freq = Counter(s)
	if len(s) == 9:
		if freq['L'] > 1 and freq['T'] > 1 and (freq['I'] > 1) and (freq['M'] > 1) and (freq['E'] >= 1):
			print('YES')
		else:
			print('NO')
	elif freq['L'] > 1 and freq['T'] > 1 and (freq['I'] > 1) and (freq['M'] > 1) and (freq['E'] > 1):
		print('YES')
	else:
		print('NO')
	t = t - 1


a = int(input())
for i in range(a):
	v = str(input())
	if v.count('L') >= 2 and v.count('T') >= 2 and (v.count('I') >= 2) and (v.count('M') >= 2) and (v.count('E') >= 2) and (len(v) > 9):
		print('YES')
	elif len(v) == 9 and v.count('L') >= 2 and (v.count('T') >= 2) and (v.count('I') >= 2) and (v.count('M') >= 2) and (v.count('E') >= 1):
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())
for i in range(t):
	s = input()
	c = Counter(s)
	if c['L'] >= 2 and c['T'] >= 2 and (c['I'] >= 2) and (c['M'] >= 2):
		if len(s) >= 10:
			if c['E'] >= 2:
				print('YES')
			else:
				print('NO')
		elif c['E'] >= 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


tests = int(input())
for i in range(tests):
	string = input()
	char_dict = {}
	for j in string:
		if j in char_dict:
			char_dict[j] += 1
		else:
			char_dict[j] = 1
	required = ['M', 'I', 'T', 'L']
	ans = 'YES'
	if 'E' not in char_dict or (len(string) >= 10 and char_dict['E'] < 2):
		ans = 'NO'
	for j in required:
		if j not in char_dict or char_dict[j] < 2:
			ans = 'NO'
			break
	print(ans)


from collections import *
for _ in range(int(input())):
	l = list(input())
	d = Counter(l)
	if d['L'] >= 2 and d['T'] >= 2 and (d['I'] >= 2) and (d['M'] >= 2):
		if len(l) == 9 and d['E'] >= 1:
			print('YES')
		elif d['E'] >= 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	s = list(input())
	n = len(s)
	dic = Counter(s)
	l = [('L', 2), ('T', 2), ('I', 2), ('M', 2)]
	arr = list(dic.keys())
	if n < 9:
		print('NO')
	elif n == 9:
		flag = True
		for i in l:
			if i[0] not in arr:
				flag = False
				break
			elif 2 > dic[i[0]]:
				flag = False
				break
		if flag:
			if 'E' not in arr:
				flag = False
			elif 1 > dic['E']:
				flag = False
		if flag:
			print('YES')
		else:
			print('NO')
	elif n > 9:
		flag = True
		for i in l:
			if i[0] not in arr:
				flag = False
				break
			elif 2 > dic[i[0]]:
				flag = False
				break
		if flag:
			if 'E' not in arr:
				flag = False
			elif 2 > dic['E']:
				flag = False
		if flag:
			print('YES')
		else:
			print('NO')


try:
	from debug import debug, timer
except ImportError:
	pass
from sys import stdin
input = stdin.readline

def rii():
	return range(int(input().strip()))

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

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

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

def si():
	return str(input().strip())

def getvals():
	while True:
		yield from input().split()

def tri(n):
	return n * (n + 1) // 2

def smallest_first(m, n):
	return (min(m, n), max(m, n))
from collections import Counter
phrase = 'LTIME'
(success, failure) = ('YES', 'NO')

def solve(s):
	if len(s) < 9:
		return failure
	counter_s = Counter(s)
	if len(s) > 9:
		return success if all([counter_s[x] >= 2 for x in phrase]) else failure
	else:
		return success if all([counter_s[x] == 2 for x in phrase[:4]] + [counter_s['E'] == 1]) else failure

def do_codechef():
	for t in rii():
		print(solve(si()))
do_codechef()
exit()


t = int(input())
while t:
	s = input()
	if s.count('E') >= 2 and s.count('M') >= 2 and (s.count('I') >= 2) and (s.count('T') >= 2) and (s.count('L') >= 2):
		print('YES')
	elif s.count('E') == 1 and len(s) == 9 and (s.count('L') >= 2) and (s.count('T') >= 2) and (s.count('I') >= 2) and (s.count('M') >= 2):
		print('YES')
	else:
		print('NO')
	t -= 1


from collections import Counter
for i in range(int(input())):
	s = input().upper()
	res = Counter(s)
	if res['L'] >= 2 and res['T'] >= 2 and (res['I'] >= 2) and (res['M'] >= 2):
		if len(s) == 9:
			if res['E'] >= 1:
				print('YES')
			else:
				print('NO')
		elif len(s) > 9:
			if res['E'] >= 2:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
while t:
	s = input()
	f = 1
	for i in 'MITL':
		if s.count(i) < 2:
			f = 0
			break
	if f:
		if len(s) == 9:
			if s.count('E'):
				print('YES')
			else:
				print('NO')
		elif s.count('E') > 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	t -= 1


te = int(input())
for _ in range(te):
	s = input()
	l = s.count('L')
	if l < 2:
		print('NO')
		continue
	t = s.count('T')
	if t < 2:
		print('NO')
		continue
	i = s.count('I')
	if i < 2:
		print('NO')
		continue
	m = s.count('M')
	if m < 2:
		print('NO')
		continue
	e = s.count('E')
	c = 1 if len(s) == 9 else 2
	if e < c:
		print('NO')
		continue
	print('YES')


t = int(input())
for i in range(t):
	s = str(input())
	if s.count('L') >= 2 and s.count('T') >= 2 and (s.count('I') >= 2) and (s.count('M') >= 2) and (s.count('E') >= 2) or (len(s) == 9 and s.count('L') >= 2 and (s.count('T') >= 2) and (s.count('I') >= 2) and (s.count('M') >= 2) and (s.count('E') >= 0)):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	v = {'L': 0, 'T': 0, 'I': 0, 'M': 0, 'E': 0}
	for c in s:
		if c in v:
			v[c] += 1
	f = 0
	for (k, v) in v.items():
		if v == 0:
			f = 1
			break
		elif v == 1:
			if k != 'E' or (k == 'E' and len(s) > 9):
				f = 1
				break
	print('NO' if f == 1 else 'YES')


for i in range(int(input())):
	s = input()
	n = len(s)
	(L, T, M, I, E) = (0, 0, 0, 0, 0)
	for i in range(n):
		if s[i] == 'L':
			L = L + 1
		elif s[i] == 'T':
			T = T + 1
		elif s[i] == 'I':
			I = I + 1
		elif s[i] == 'M':
			M = M + 1
		elif s[i] == 'E':
			E = E + 1
	if L > 1 and T > 1 and (I > 1) and (M > 1) and (E > 1):
		print('YES')
	elif L == 2 and T == 2 and (I == 2) and (M == 2) and (E == 1 or E == 2):
		print('YES')
	elif n == 5 and L == 1 and (T == 1) and (I == 1) and (M == 1) and (E == 1):
		print('YES')
	else:
		print('NO')


import string
t = int(input())
while t:
	t = t - 1
	s = input()
	arr = list(s)
	d = dict(zip(string.ascii_uppercase, [0] * 26))
	for c in arr:
		d[c] += 1
	if d['L'] >= 2 and d['T'] >= 2 and (d['I'] >= 2) and (d['M'] >= 2) and (d['E'] >= 1):
		if len(s) > 9 and d['E'] == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = input()
	if len(n) < 9:
		print('NO')
		continue
	counter = [0] * 26
	found = False
	for i in n:
		counter[ord(i) - ord('A')] += 1
	ltime = [ord('L') - ord('A'), ord('T') - ord('A'), ord('I') - ord('A'), ord('M') - ord('A')]
	e = ord('E') - ord('A')
	for j in ltime:
		if counter[j] < 2:
			found = True
			break
	if found or counter[e] == 0:
		print('NO')
	elif len(n) == 9 and counter[e] > 0:
		print('YES')
	elif counter[e] > 1:
		print('YES')
	else:
		print('NO')


def solve(s):
	if len(s) < 5:
		return 'NO'
	mp = {'L': 0, 'T': 0, 'I': 0, 'M': 0, 'E': 0}
	for i in range(len(s)):
		if s[i] in mp:
			mp[s[i]] += 1
	for (key, val) in mp.items():
		if val < 2:
			if key == 'E' and len(s) == 9:
				continue
			else:
				return 'NO'
	return 'YES'
for _ in range(int(input())):
	s = input()
	print(solve(s))


test = int(input())
while test != 0:
	test -= 1
	l = [0, 0, 0, 0, 0]
	s = input()
	for i in range(len(s)):
		if s[i] == 'L':
			l[0] += 1
		if s[i] == 'T':
			l[1] += 1
		if s[i] == 'I':
			l[2] += 1
		if s[i] == 'M':
			l[3] += 1
		if s[i] == 'E':
			l[4] += 1
	if l[0] >= 2 and l[1] >= 2 and (l[2] >= 2) and (l[3] >= 2) and (l[4] >= 2):
		print('YES')
	elif len(s) < 10 and len(s) >= 5:
		if len(s) == 9:
			if l[0] >= 2 and l[1] >= 2 and (l[2] >= 2) and (l[3] >= 2) and (l[4] >= 1):
				print('YES')
			else:
				print('NO')
		if len(s) == 8:
			if l[0] >= 2 and l[1] >= 2 and (l[2] >= 2) and (l[3] >= 1) and (l[4] >= 1):
				print('YES')
			else:
				print('NO')
		if len(s) == 7:
			if l[0] >= 2 and l[1] >= 2 and (l[2] >= 1) and (l[3] >= 1) and (l[4] >= 1):
				print('YES')
			else:
				print('NO')
		if len(s) == 6:
			if l[0] >= 2 and l[1] >= 1 and (l[2] >= 1) and (l[3] >= 1) and (l[4] >= 1):
				print('YES')
			else:
				print('NO')
		if len(s) == 5:
			if l[0] >= 1 and l[1] >= 1 and (l[2] >= 1) and (l[3] >= 1) and (l[4] >= 1):
				print('YES')
			else:
				print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	d = {}
	sub = 'LTIM'
	for ele in s:
		try:
			d[ele] += 1
		except:
			d[ele] = 1
	for ele in sub:
		try:
			if d[ele] < 2:
				throw
		except:
			print('NO')
			break
	else:
		if s.count('E') == 1 and len(s) == 9 or s.count('E') > 1:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	s = input()
	flag = 0
	if len(s) < 9:
		flag = 1
	elif s.count('L') < 2 or s.count('T') < 2 or s.count('I') < 2 or (s.count('M') < 2):
		flag = 1
	if (s.count('E') == 1 and len(s) == 9 or s.count('E') >= 2) and flag != 1:
		flag = 0
	else:
		flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	s = input()
	s1 = s2 = s3 = s4 = s5 = 0
	for i in range(len(s)):
		if s[i] == 'L':
			s1 += 1
		if s[i] == 'T':
			s2 += 1
		if s[i] == 'I':
			s3 += 1
		if s[i] == 'M':
			s4 += 1
		if s[i] == 'E':
			s5 += 1
	if s1 >= 2 and s2 >= 2 and (s3 >= 2) and (s4 >= 2) and (s5 >= 2) and (len(s) > 9):
		print('YES')
	elif s1 >= 2 and s2 >= 2 and (s3 >= 2) and (s4 >= 2) and (s5 >= 1) and (len(s) == 9):
		print('YES')
	else:
		print('NO')


x = ['L', 'T', 'I', 'M', 'E']
for t in range(int(input())):
	s = input()
	l = len(s)
	if l < 9:
		print('NO')
		continue
	elif l == 9:
		count = [0, 0, 0, 0, 0]
		for i in s:
			if i == 'L':
				count[0] += 1
			elif i == 'T':
				count[1] += 1
			elif i == 'I':
				count[2] += 1
			elif i == 'M':
				count[3] += 1
			elif i == 'E':
				count[4] += 1
		if count == [2, 2, 2, 2, 1]:
			print('YES')
		else:
			print('NO')
		continue
	else:
		count = [0, 0, 0, 0, 0]
		for i in s:
			if i == 'L':
				count[0] += 1
			elif i == 'T':
				count[1] += 1
			elif i == 'I':
				count[2] += 1
			elif i == 'M':
				count[3] += 1
			elif i == 'E':
				count[4] += 1
		flag = 0
		for i in count:
			if i < 2:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')
		continue


import sys
import math
from queue import Queue
import heapq

def main(s):
	freq = {}
	r = 'LTIME'
	for letter in s:
		if letter not in freq:
			freq[letter] = 0
		freq[letter] += 1
	for letter in r:
		if letter not in freq:
			return 'NO'
		if freq[letter] >= 2 or (len(s) == 9 and letter == 'E' and (freq[letter] == 1)):
			continue
		else:
			return 'NO'
	return 'YES'
t = int(input())
for i in range(t):
	s = input()
	print(main(s))


t = int(input())
while t > 0:
	data = list(input())
	if data.count('L') >= 2 and data.count('T') >= 2 and (data.count('I') >= 2) and (data.count('M') >= 2) and (data.count('E') >= 2):
		print('YES')
	elif len(data) == 9 and data.count('L') >= 2 and (data.count('T') >= 2) and (data.count('I') >= 2) and (data.count('M') >= 2) and (data.count('E') == 1):
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
for _ in range(t):
	s = input()
	d = {}
	for i in s:
		try:
			d[i] += 1
		except:
			d[i] = 1
	if len(s) < 5:
		print('NO')
	elif len(s) == 5:
		s = sorted(s)
		if ''.join(s) == 'EILMT':
			print('YES')
		else:
			print('NO')
	else:
		a = 0
		s = sorted(s)
		if ''.join(s) == 'EIILLMMTT':
			print('YES')
		else:
			k = 'LTIME'
			a = 0
			for j in k:
				try:
					x = d[j]
					if x >= 2:
						a += 1
				except:
					pass
			if a == 5:
				print('YES')
			else:
				print('NO')


t = int(input())
for l in range(1, t + 1):
	s = input()
	s = list(s)
	s.sort()
	if s == ['E', 'I', 'I', 'L', 'L', 'M', 'M', 'T', 'T']:
		print('YES')
	else:
		to = list('LTIME')
		o = 0
		for i in to:
			for j in range(2):
				if i in s:
					s.remove(i)
					o += 1
		if o == 10:
			print('YES')
		else:
			print('NO')


def possible(s):
	for i in 'LTIM':
		if s.count(i) < 2:
			return False
	if len(s) == 9:
		if s.count('E') < 1:
			return False
	elif s.count('E') < 2:
		return False
	return True
for T in range(int(input())):
	S = input()
	if possible(S):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	str1 = input()
	a = str1.count('L')
	b = str1.count('T')
	c = str1.count('M')
	d = str1.count('I')
	e = str1.count('E')
	if len(str1) == 9 and a == 2 and (b == 2) and (c == 2) and (d == 2) and (e == 1):
		print('YES')
	elif a >= 2 and b >= 2 and (c >= 2) and (d >= 2) and (e >= 2):
		print('YES')
	else:
		print('NO')


T = int(input())
strings = []
for x in range(0, T):
	strings.append(str(input()))
for s in strings:
	e = s.count('E')
	m = s.count('M')
	i = s.count('I')
	t = s.count('T')
	l = s.count('L')
	if len(s) > 9 and e >= 2 and (m >= 2) and (i >= 2) and (t >= 2) and (l >= 2):
		print('YES')
	elif len(s) == 9 and e >= 1 and (m >= 2) and (i >= 2) and (t >= 2) and (l >= 2):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	A = input()
	L_array = [0 for i in range(5)]
	for i in A:
		if i == 'L':
			L_array[0] += 1
		if i == 'T':
			L_array[1] += 1
		if i == 'I':
			L_array[2] += 1
		if i == 'M':
			L_array[3] += 1
		if i == 'E':
			L_array[4] += 1
	ans = ''
	flag = 0
	for i in range(4):
		if L_array[i] >= 2:
			flag += 1
	if L_array[4] >= 2:
		flag += 1
	elif L_array[4] == 1 and len(A) == 9:
		flag += 1
	if flag < 5:
		print('NO')
	else:
		print('YES')


case = int(input())
for z in range(case):
	s = input()
	d = {'L': 0, 'T': 0, 'I': 0, 'M': 0, 'E': 0}
	for i in range(len(s)):
		if s[i] == 'L' or s[i] == 'T' or s[i] == 'I' or (s[i] == 'M') or (s[i] == 'E'):
			d[s[i]] = d[s[i]] + 1
	if d['L'] >= 2 and d['T'] >= 2 and (d['I'] >= 2) and (d['M'] >= 2) and (d['E'] >= 1):
		if len(s) == 9 and d['E'] == 1:
			print('YES')
		elif d['E'] >= 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	s = input()
	c = Counter(s)
	for i in 'LTIME':
		if c[i] < 2:
			if i != 'E':
				print('NO')
				break
			elif i == 'E' and c[i] == 1 and (len(s) > 9):
				print('NO')
				break
	else:
		print('YES')


from collections import Counter
for i in range(int(input())):
	S = input()
	A = dict(Counter(S))
	flag = 0
	li = ['L', 'I', 'T', 'M', 'E']
	for i in li:
		if i not in A:
			flag = 1
			break
	if flag != 1:
		if len(S) > 9:
			for i in li:
				if A[i] < 2:
					flag = 1
					break
		if len(S) == 9:
			for i in li:
				if A[i] < 2 and i != 'E':
					flag = 1
					break
				if i == 'E' and flag != 1:
					if A[i] < 1:
						flag = 1
						break
		if len(S) < 9:
			flag = 1
	if flag != 1:
		print('YES')
	else:
		print('NO')


def check(l):
	for i in l:
		if i < 2:
			print('NO')
			return
	print('YES')
	return
for _ in range(int(input())):
	s = input()
	l = [0] * 5
	for i in range(len(s)):
		if s[i] == 'L':
			l[0] += 1
		elif s[i] == 'T':
			l[1] += 1
		elif s[i] == 'I':
			l[2] += 1
		elif s[i] == 'M':
			l[3] += 1
		elif s[i] == 'E':
			l[4] += 1
	if len(s) == 9:
		if l[0] == 2 and l[1] == 2 and (l[2] == 2) and (l[3] == 2) and (l[4] == 1):
			print('YES')
		else:
			print('NO')
		continue
	check(l)


T = int(input())
for i in range(T):
	E = 0
	M = 0
	I = 0
	T = 0
	L = 0
	Russia = input()
	for letter in Russia:
		if letter == 'E':
			E = E + 1
		if letter == 'M':
			M = M + 1
		if letter == 'I':
			I = I + 1
		if letter == 'T':
			T = T + 1
		if letter == 'L':
			L = L + 1
	if E >= 2 and M >= 2 and (I >= 2) and (T >= 2) and (L >= 2):
		print('YES')
	elif E == 1 and M >= 2 and (I >= 2) and (T >= 2) and (L >= 2) and (len(Russia) == 9):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	fake = False
	if s.count('T') < 2:
		fake = True
	if s.count('E') < 2:
		fake = True
	if s.count('M') < 2:
		fake = True
	if s.count('L') < 2:
		fake = True
	if s.count('I') < 2:
		fake = True
	if len(s) == 9 and s.count('T') == 2 and (s.count('E') == 1) and (s.count('M') == 2) and (s.count('I') == 2) and (s.count('L') == 2):
		fake = False
	if fake == False:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	string = input()
	check = 'LTIME'
	j = 0
	count = 0
	k = -1
	if len(string) == 9:
		if string.count('L') == 2 and string.count('M') == 2 and (string.count('I') == 2) and (string.count('T') == 2) and (string.count('E') == 1):
			print('YES')
		else:
			print('NO')
	else:
		while True:
			k += 1
			if k == len(string):
				if count >= 2:
					j += 1
					k = -1
					count = 0
				else:
					print('NO')
					break
			if j == 5:
				print('YES')
				break
			if k != -1 and string[k] == check[j]:
				count += 1


from collections import defaultdict
LETTERS = ['M', 'I', 'T', 'L']

def main():
	for __ in range(int(input())):
		string = input()
		data = defaultdict(int)
		for character in string:
			data[character] = string.count(character)
		if 0 in [0 for letter in LETTERS if data[letter] < 2]:
			print('NO')
			continue
		if data['E'] >= 2 or (data['E'] == 1 and len(data) == 5):
			print('YES')
			continue
		print('NO')
main()


t = int(input())
for i in range(0, t):
	s = input()
	l = len(s)
	f = 0
	l1 = 0
	t1 = 0
	i1 = 0
	m = 0
	e = 0
	if l < 9:
		f = 1
	else:
		for j in s:
			if j == 'L':
				l1 += 1
			elif j == 'T':
				t1 += 1
			elif j == 'I':
				i1 += 1
			elif j == 'M':
				m += 1
			elif j == 'E':
				e += 1
	if l1 >= 2 and t1 >= 2 and (i1 >= 2) and (m >= 2) and (f != 1):
		if l == 9 and e == 1 or e >= 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')