#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
const int L = 1000000;
const int A = 26;
const int inf = 1e9;
vector<vector<int> > nxt[N];
char s[L + 1];
int n, l, m, tmp[A], idx[N], nextindex[N][A], firstoccur[N][A], fstindex[A],
    fstpos[A];
pair<int, int> ans[N + 1][N + 1], pos, nxtpos;
const pair<int, int> inf_pair = make_pair(inf, inf);
pair<int, int> get_next(pair<int, int> pos, int ch) {
  if (pos.first == -1) {
    int nxtnum = fstindex[ch];
    if (nxtnum == -1) return make_pair(inf, inf);
    return make_pair(nxtnum, firstoccur[idx[nxtnum]][ch]);
  }
  if (nxt[idx[pos.first]][pos.second][ch] != -1)
    return make_pair(pos.first, nxt[idx[pos.first]][pos.second][ch]);
  int nxtnum = nextindex[pos.first][ch];
  if (nxtnum == -1) return make_pair(inf, inf);
  return make_pair(nxtnum, firstoccur[idx[nxtnum]][ch]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    l = strlen(s);
    memset(tmp, -1, sizeof(tmp));
    nxt[i].resize(l);
    for (int j = l - 1; j >= 0; --j) {
      nxt[i][j].resize(A);
      for (int ch = 0; ch < A; ++ch) nxt[i][j][ch] = tmp[ch];
      tmp[s[j] - 'a'] = j;
    }
    for (int ch = 0; ch < A; ++ch) firstoccur[i][ch] = tmp[ch];
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &idx[i]);
    idx[i]--;
  }
  memset(tmp, -1, sizeof(tmp));
  for (int i = m - 1; i >= 0; --i) {
    for (int ch = 0; ch < A; ++ch) nextindex[i][ch] = tmp[ch];
    for (int ch = 0; ch < A; ++ch)
      if (firstoccur[idx[i]][ch] != -1) tmp[ch] = i;
  }
  for (int ch = 0; ch < A; ++ch) fstindex[ch] = tmp[ch];
  scanf("%s", s);
  n = strlen(s);
  for (int len = 0; len <= n; ++len)
    for (int i = 0; i <= n; ++i) ans[len][i] = inf_pair;
  ans[0][0] = make_pair(-1, -1);
  for (int len = 0; len < n; ++len)
    for (int i = 0; i < n; ++i) {
      pos = ans[len][i];
      if (pos != inf_pair) {
        ans[len][i + 1] = min(ans[len][i + 1], ans[len][i]);
        nxtpos = get_next(ans[len][i], s[i] - 'a');
        ans[len + 1][i + 1] = min(ans[len + 1][i + 1], nxtpos);
      }
    }
  for (int len = n; len >= 0; --len)
    for (int i = 0; i <= n; ++i)
      if (ans[len][i] != inf_pair) {
        printf("%d\n", len);
        return 0;
      }
  return 0;
}
