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.

Starter code:

Solutions:
# cook your dish here
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")
    


# cook your dish here
from collections import Counter
for _ in range(int(input())):
 s=input()
 c=Counter(s)
 #LTIME
 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')
  


# cook your dish here
from collections import Counter
for _ in range(int(input())):
 s=input()
 c=Counter(s)
 #LTIME
 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')
  


# cook your dish here
from collections import Counter
for _ in range(int(input())):
 
 c=Counter(input())
 #LTIME
 if c['L']>=2 and c['T']>=2 and c['I']>=2 and c['M']>=2 and c['E']>=1:
  print('YES')
 else:
  print('NO')
  


# cook your dish here
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")
  else:
   if s.count('E')>1:
    print("YES")
   else:
    print("NO")
 else:
  print("NO")
 t-=1

# cook your dish here
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")

for _ in range(int(input())):
 s=input()
 flag=0
 if len(s)<9:
  flag=1
 else:    
  if 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")

# cook your dish here
for _ in range(int(input())):
 s=input()
 flag=0
 if len(s)<9:
  flag=1
 else:    
  if 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")

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')


# cook your dish here
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")

t = int(input())
for T in range(t):
 s = input()
 l = s.count("L")
 t = s.count("T")
 i = s.count("I")
 m = s.count("M")
 e = s.count("E")

 if min(l, t, i, m, e) >= 2 and len(s) > 9:
  print("YES")
 elif min(l, t, i, m) >= 2 and e >= 1 and len(s) == 9:
  print("YES")
 else:
  print("NO")


# God Bless
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
 else:
  if s.count('E') < 2:
   return False
   
 return True

for T in range(int(input())):
 S = input()
 
 if possible(S):
  print('YES')
 else:
  print('NO')