

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=3e4+10,M=5e2+10,sed=31,SED=131,mod=70177,MOD=92311;
int n,m,p,q,ans,tot,hd[mod],nx[N*2],ver[N*2],cnt[N*2],Hash[N],HASH[N];
struct node{
char s[M];
inline bool operator<(const node&rhs)const{
return strcmp(s,rhs.s)<0;}
}a[N];
inline void Insert(const int &x,const int &y)
{
for(int i=hd[x];i;i=nx[i])
if(ver[i]==y){++cnt[i];return;}
nx[++tot]=hd[x];hd[x]=tot;ver[tot]=y;cnt[tot]=1;
return;
}
inline int query(const int &x,const int &y)
{
for(int i=hd[x];i;i=nx[i])
if(ver[i]==y)return cnt[i];
return 0;
}
inline void solve1()
{
int tmp,TMP;ans=-1;
for(int i=0;i<n;i++)
{
tmp=TMP=0;
for(int j=0;j<m;j++)
{
tmp=(tmp*sed+(a[i].s[j]=='N'))%mod;
TMP=(TMP*SED+(a[i].s[j]=='N'))%MOD;
}
Hash[i]=tmp,HASH[i]=TMP;
Insert(tmp,TMP);
}
for(int i=0;i<n;i++)
if(query(Hash[i],HASH[i])==p)//当成满分有p个
{
tmp=TMP=0;
for(int j=0;j<m;j++)//求出零分答案
{
tmp=(tmp*sed+(a[i].s[j]=='Y'))%mod;
TMP=(TMP*SED+(a[i].s[j]=='Y'))%MOD;
}
if(query(tmp,TMP)=