#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3fll;
long long int getint() {
  long long int ret = 0;
  bool f = 0;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f ^= 1;
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return f ? -ret : ret;
}
using namespace std;
const int MAXN = 2000;
const int MAXL = 1002000;
int f[MAXN + 10][MAXN + 10];
int p[MAXN + 10], length[MAXN + 10];
char s[MAXL + 10], b[MAXN + 10];
int nxt[MAXL + 10][26];
int fnxt[MAXN + 10][26];
int tmp[26], rk[MAXN + 10], sumlen[MAXN + 10];
int main() {
  int n = getint();
  f[0][0] = 0;
  int pos = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + pos + 1);
    p[i] = pos;
    int len = length[i] = strlen(s + pos + 1);
    memset(tmp, 0, sizeof tmp);
    for (int j = len; j >= 1; --j) {
      tmp[s[j + pos] - 'a'] = j;
      memcpy(nxt[j + pos], tmp, sizeof tmp);
    }
    pos += len + 1;
  }
  int m = getint();
  for (int i = 1; i <= m; ++i) {
    rk[i] = getint();
    sumlen[i] = sumlen[i - 1] + length[rk[i]];
  }
  memset(tmp, 0, sizeof tmp);
  for (int i = m; i >= 1; --i) {
    int c = rk[i];
    for (int j = 0; j < 26; ++j)
      if (nxt[p[c] + 1][j]) tmp[j] = nxt[p[c] + 1][j] + sumlen[i - 1];
    memcpy(fnxt[i], tmp, sizeof tmp);
  }
  scanf("%s", b + 1);
  int len = strlen(b + 1);
  memset(f, -1, sizeof f);
  f[0][0] = 0;
  int ans = 0;
  for (int j = 1; j <= len; ++j) {
    f[j][0] = 0;
    for (int k = 1; k <= j; ++k)
      if (~f[j - 1][k - 1]) {
        int i = f[j - 1][k - 1] + 1;
        int c = b[j] - 'a';
        int blk = lower_bound(sumlen + 1, sumlen + m + 1, i) - sumlen;
        if (blk > m) {
          f[j][k] = f[j - 1][k];
          continue;
        }
        int r = rk[blk];
        pos = i - sumlen[blk - 1];
        if (nxt[p[r] + pos][c])
          f[j][k] = nxt[p[r] + pos][c] + sumlen[blk - 1];
        else if (fnxt[blk + 1][c])
          f[j][k] = fnxt[blk + 1][c];
        else
          f[j][k] = f[j - 1][k];
        if ((~f[j - 1][k]) && (~f[j - 1][k]))
          f[j][k] = min(f[j - 1][k], f[j][k]);
        if (~f[j][k]) ans = max(ans, k);
      } else
        f[j][k] = f[j - 1][k];
  }
  printf("%d\n", ans);
}
