#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[2001], sum[2001], nxt1[1000009][26], nxt2[2009][26], nxt3[2009][26],
    dp[2001][2001];
string s, base[2001];
int _nxt(int id, int i, int j) { return nxt1[sum[id - 1] + i][j]; }
int nxt(int t, int k) {
  int l = t & 1048575;
  t >>= 20;
  if (!t) return nxt3[1][k];
  if (_nxt(p[t], l, k) != -1) return t << 20 | _nxt(p[t], l, k);
  return nxt3[t + 1][k];
}
void init_nxt(int a[][26], string &s) {
  int n = s.size();
  for (int i = 0; i < 26; i++) a[n][i] = -1;
  for (int i = n - 1; i >= 0; i--)
    for (int j = 0; j < 26; j++)
      a[i][j] = (j + 'a' == s[i + 1] ? i + 1 : a[i + 1][j]);
}
void checkmin(int &a, int b) {
  if (a == -1 || a > b) a = b;
}
int main() {
  while (scanf("%d", &n) + 1) {
    for (int i = 1; i <= n; i++) {
      cin >> base[i];
      init_nxt(&nxt1[sum[i - 1]], base[i]);
      sum[i] = sum[i - 1] + base[i].size();
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) scanf("%d", p + i);
    for (int i = 0; i < 26; i++) nxt3[m + 1][i] = -1;
    for (int i = m; i; i--)
      for (int j = 0; j < 26; j++) {
        if (base[p[i]][0] == 'a' + j)
          nxt3[i][j] = i << 20;
        else if (_nxt(p[i], 0, j) != -1)
          nxt3[i][j] = i << 20 | _nxt(p[i], 0, j);
        else
          nxt3[i][j] = nxt3[i + 1][j];
      }
    cin >> s;
    init_nxt(nxt2, s);
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    dp[0][1] = nxt(0, s[0] - 'a');
    int t, ans = 0;
    for (int i = 0; s[i]; i++)
      for (int j = 0; j <= i + 1; j++) {
        if (dp[i][j] == -1) continue;
        ans = max(ans, j);
        for (int k = 0; k < 26; k++)
          if (nxt2[i][k] != -1 && (t = nxt(dp[i][j], k)) != -1)
            checkmin(dp[nxt2[i][k]][j + 1], t);
      }
    printf("%d\n", ans);
  }
  return 0;
}
