#include <bits/stdc++.h>
using namespace std;
int n, len[2009], m, pos[2009], now[26], last[1002009][26], id[2009],
    go[2009][26], L, Ans;
int dp[1002009][2], sum[2009];
char a[1002009], s[2009];
int read() {
  int x = 1;
  char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') x = -1;
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
  return s * x;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    memset(now, 0, sizeof(now));
    scanf("%s", a + 1);
    len[i] = strlen(a + 1);
    pos[i + 1] = pos[i] + len[i] + 1;
    for (int j = len[i]; j >= 0; j--) {
      for (int k = 0; k < 26; k++) last[pos[i] + j][k] = now[k];
      if (j) now[a[j] - 'a'] = j;
    }
  }
  m = read();
  for (int i = 1; i <= m; i++) {
    id[i] = read();
    sum[i] = sum[i - 1] + len[id[i]];
  }
  scanf("%s", s + 1);
  L = strlen(s + 1);
  memset(now, 0, sizeof(now));
  for (int i = m; i; i--) {
    for (int k = 0; k < 26; k++) go[i][k] = now[k];
    for (int k = 0; k < 26; k++)
      if (last[pos[id[i]]][k]) now[k] = i;
  }
  dp[0][0] = 1, dp[0][1] = 0;
  for (int i = 1; i <= L; i++) {
    for (int j = Ans; j >= 0; j--) {
      int ID = 0, POS = 0, c = s[i] - 'a';
      if (last[pos[id[dp[j][0]]] + dp[j][1]][c])
        ID = dp[j][0], POS = last[pos[id[dp[j][0]]] + dp[j][1]][c];
      else
        ID = go[dp[j][0]][c], POS = last[pos[id[ID]]][c];
      if (ID && (dp[j + 1][0] == 0 ||
                 sum[ID - 1] + POS < sum[dp[j + 1][0] - 1] + dp[j + 1][1]))
        dp[j + 1][0] = ID, dp[j + 1][1] = POS;
    }
    if (dp[Ans + 1][0]) Ans++;
  }
  printf("%d\n", Ans);
  return 0;
}
