#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <stack>
#define M 100000
typedef struct Node{
int count;
struct Node *next[27];
}Node;
Node vec[M];
int cnt;
Node *root;
int sum;
void Initial()
{
int i,j;
for(i = 0;i < M;i++)
{
vec[i].count = 0;
for(j = 0;j < 27;j++)
vec[i].next[j] = NULL;
}
cnt = sum = 0;
}
void trie_built(char *s)
{
Node *r = root;
int len = strlen(s);
int t;
int flage = 1;
for(int i = 0;i < len;i++)
{
t = s[i] - 'a' + 1;
if(r->next[t] == NULL){
r->next[t] = &vec[cnt++];
r = r->next[t];
r->count++;
}
else{
r = r->next[t];
r->count++;
}
}
}
int Find(char *s)
{
Node *r = root;
int i,t;
int len = strlen(s);
for(i = 0;i < len;i++)
{
t = s[i] - 'a' + 1;
if(r->next[t] == NULL)
return 0;
else{
r = r->next[t];
if(i == len-1) return r->count;
}
}
return 0;
}
int main()
{
//freopen("in.in","r",stdin);
int m,n,i,j,k,t;
char str[60];
char ss[100];
double num[8];
int bit[8];
while(scanf("%d%d",&n,&m)!=EOF)
{
Initial();
getchar();
root = &vec[cnt++];
for(i=0;i<n;i++){
gets(str);
trie_built(str);
}
int sum=0;
while(m--)
{
scanf("%d",&k);
for(i=0;i<k;i++)
{
scanf("%lf",&num[0]);
double max=num[0]/0.95*1.05;
bit[0]=0;
for(j=1;j<8;j++)
{
scanf("%lf",&num[j]);
if(num[j]-max>0)
bit[j]=1;
else
bit[j]=0;
}
ss[i]=1;
for(j=2;j<8;j++)
ss[i]=ss[i]*2+bit[j];
}
ss[k]='\0';
sum += Find(ss);
}
printf("%d\n",sum);
}
return 0;
}