/* package codechef; // don’t place package name! */
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner n = new Scanner(System.in);
String x=“”;
char [] a= new char [1000];
int T,N,c=0,e=0,f=0,d=0,h=0,o=0,i,j,count=0,magic,magic1=0;;
T=n.nextInt();
if(T>=1 && T<=100)
{
while(T!=0)
{
N=n.nextInt();
if(N>=1 && N<=100)
{
for(i=0;i<=N;i++)
{
x+=n.nextLine();
}
a=x.toCharArray();
for(j=0;j<x.length();j++)
{
if(a[j]=='c')
{
c++;
}
if(a[j]=='e')
{
e++;
}
if(a[j]=='d')
{
d++;
}
if(a[j]=='f')
{
f++;
}
if(a[j]=='h')
{
h++;
}
if(a[j]=='o')
{
o++;
}
}
if(c>0 && e>0&& o>0 && d>0 && h>0 && f>0)
{
if(c>e||c==e)
{
magic=e;
}
else
{
magic=c;
}
if(d<o || d<f || d<h )
{
magic1=d;
}
else if(o<d || o<f || o<h )
{
magic1=o;
}
else if(f<o || f<d || f<h )
{
magic1=f;
}
else if(h<o || h<f || h<d )
{
magic1=h;
}
else
{
magic1=d;
}
if(magic<magic1)
{
magic1=magic;
}
while(magic1!=0)
{
count++;
magic1--;
}
}
}
System.out.println(count);
count-=count;
c=0;e=0;f=0;d=0;h=0;o=0;magic1=0;magic=0;
x="";
T--;
}
}
}
}