#include <bits/stdc++.h>
using namespace std;
int main() {
 int n,m,counter,subcounter;
 string strn,strm;
 cin >> n;
 subcounter = 0;
 vector<string> vecn(0);
 vector<string> vecm(0);
 for (int i = 0; i < n; i++) {
   cin >> strn;
   vecn.push_back(strn);
 }
 cin >> m;
 for (int i = 0; i < m; i++) {
   cin >> strm;
   vecm.push_back(strm);
 }
 for (int i = 0; i < n; i++) {
   counter = 0;
   for (int j = 0; j < n; j++) {
     if  (vecn.at(i) == vecn.at(j)) {
       counter++;
     }
   }
   for (int j = 0; j < m; j++) {
     if (vecn.at(i) == vecm.at(j)) {
       counter = counter -1;
     }
   }
   if (counter > subcounter) {
     subcounter = counter;
   }
 }
 if (subcounter <= 0 ) {
   subcounter = 0;
 }
 
 cout << subcounter;
}

#include<iostream>
#include<cstring>
using namespace std;

int main(){
  int dice[6],i,dif[6],len;
  string str;
  /********サイコロの目の入力*********/
  for(i = 0 ; i < 6 ; i++)
    {
      cin >> dice[i];
    }
  cin >> str;
  len = str.size();
  for ( int j = 0 ; j < len ; j++){
    if(str[j] == 'S')
      {
	dif[0] = dice[4];
	dif[1] = dice[0];
	dif[2] = dice[2];
	dif[3] = dice[3];
	dif[4] = dice[5];
	dif[5] = dice[1];
      }
    else if (str[j] == 'W')
      {
	dif[0] = dice[2];
	dif[1] = dice[1];
	dif[2] = dice[5];
	dif[3] = dice[0];
	dif[4] = dice[4];
	dif[5] = dice[3];
      }
    else if(str[j] == 'E')
      {
	dif[0] = dice[3];
	dif[1] = dice[1];
	dif[2] = dice[0];
	dif[3] = dice[5];
	dif[4] = dice[4];
	dif[5] = dice[2];
      }
    else if (str[j] == 'N')
      {
	dif[0] = dice[1];
	dif[1] = dice[5];
	dif[2] = dice[2];
	dif[3] = dice[3];
	dif[4] = dice[0];
	dif[5] = dice[4];
      }
    
    for( i = 0 ; i < 6 ; i++)
      {
	dice[i] = dif[i];
      }
  }
  cout << dice[0] << endl;
  return 0;
}