//////////////////////////////////////////
// Debugging -- Lesson 1
// ISOLATION
//
// author:        Ali Taleghani 
// last revision: Tue. Mar 4th
//
// Matching people looking for jobs with available jobs
// has become a major incentive for employment agencies to automate
// their systems. Here is a pathetic attempt at that.
//
// JFJS (Job Finders; Job Seekers) represents each available job with 4
// strings:  The strings show employer name, position, 
// part-time/full-time, travel. The contents
// of each string is irrelevant, as they will be read by 
// by end users (... no AI module yet ;-)) 
//
// Customers of JFJS will specify their preference in positions
// using the same 4 strings, with one difference. In place of
// any of the strings, they are allowed to put '**', meaning
// they have no preference in that field. 
// For simplicity assume neither of the four strings contains
// any spaces.
// Examples illustrate.
//
//     An example description of a job available through JFJS:
// Macrosoft
// Cheif-Software-Architect
// part-time
// no travel
//
//     An example description of a customer looking for a full-time
//     junior programmer job 
// **
// junior-programmer
// full-time
// **
//
// Your job is to find matches for customers. A job description MATCHES
// a customer's preferences if and only if all fields not marked **
// are identical in the two descriptions.
//
// INPUT:
//  Input start with a number n, the number of available 
// jobs to be searched. Next come n jobs descriptions (consisting of 5
// strings each on a line by itself, exactly as shown above). These are
// the jobs to search. Then come a customer job description
// showing his/her preferences. 
//
// OUTPUT: 
//  For the customer, output the number of jobs descriptions that MATCHES
// his/her preference. 

#include <stdio.h>
#include <iostream>

using namespace std;

struct JobDesc
{
  char * employer;
  char * position;
  char * ptOrft;
  char * travel;
  int salary;
};

// arr must have memory allocated to it
void readInput (int n, JobDesc * arr)
{
  char * employer = new char[80];
  char * position = new char[80];  
  char * ptOrft = new char[80];
  char * travel = new char[80];

  int index = 0;

  while (index < n) {
    scanf("%s", employer);
    scanf("%s", position);
    scanf("%s", ptOrft);
    scanf("%s", travel);

    arr[index].employer = employer;
    arr[index].position = position;
    arr[index].ptOrft = ptOrft;
    arr[index].travel = travel;

    index++;
  }
}

bool matches(JobDesc *desc, JobDesc *preference)
{
  bool employer, position, ptOrft, travel;
  char noPref[] = "**";
  
  employer = (! strcmp (preference->employer, noPref)) || 
    ! strcmp (preference->employer, desc->employer);

  position = (! strcmp (preference->position, noPref)) || 
    ! strcmp (preference->position, desc->position);

  ptOrft   = (! strcmp (preference->ptOrft, noPref)) || 
    ! strcmp (preference->ptOrft, desc->ptOrft);

  travel = (! strcmp (preference->travel, noPref)) || 
    ! strcmp (preference->travel, desc->travel);

  return employer && position && ptOrft && travel;
}

int main()
{
  int n, count = 0;

  cin >> n;
  JobDesc *arr = new JobDesc[n];
  JobDesc *pref = new JobDesc;

  readInput(n, arr);
  readInput(1, pref);

  for (int i=0; i < n; i++)
    count += matches(arr + i, pref) ? 1 : 0;

  printf("%d\n", count);
  return 0;
}

    

  



