#include <bits/stdc++.h>
using namespace std;
int N, M;
string str;
vector<string> S;
vector<int> Q, P[2010][26];
pair<int, int> F[2010][2010], E[2010][26];
int len;
char T[2010];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    cin >> str;
    S.push_back(str);
    for (int j = 0; j < str.length(); j++) P[i][str[j] - 'a'].push_back(j);
  }
  scanf("%d", &M);
  for (int i = 0, a; i < M; i++) {
    cin >> a;
    Q.push_back(--a);
  }
  scanf("%s", T + 1);
  len = strlen(T + 1);
  memset(E, -1, sizeof(E));
  for (int i = 0; i < Q.size() - 1; i++)
    for (int j = 0; j < 26; j++) {
      int t = i + 1;
      while (t < Q.size() && P[Q[t]][j].empty()) t++;
      if (t < Q.size() && !P[Q[t]][j].empty())
        E[i][j] = make_pair(t, P[Q[t]][j][0]);
      else
        E[i][j] = make_pair(-1, -1);
    }
  vector<int>::iterator it;
  memset(F, -1, sizeof(F));
  for (int i = 1; i <= len; i++)
    for (int j = 1; j <= i; j++) {
      int s = T[i] - 'a';
      pair<int, int> x, y, m;
      x = F[i - 1][j], y = F[i - 1][j - 1], m = make_pair(-1, -1);
      if (y.first != -1) {
        it = upper_bound(P[Q[y.first]][s].begin(), P[Q[y.first]][s].end(),
                         y.second);
        if (it != P[Q[y.first]][s].end())
          m = make_pair(y.first, *it);
        else
          m = E[y.first][s];
      } else if (j == 1) {
        it = lower_bound(P[Q[0]][s].begin(), P[Q[0]][s].end(), 0);
        if (it != P[Q[0]][s].end())
          m = make_pair(0, *it);
        else
          m = E[0][s];
      }
      F[i][j] = x;
      if (x.first == -1 || (m.first != -1 && m < x)) F[i][j] = m;
    }
  int ans = 0;
  for (int i = len; i >= 0; i--)
    if (F[len][i].first != -1) {
      ans = i;
      break;
    }
  cout << ans << endl;
  return 0;
}
