#include <bits/stdc++.h>
using namespace std;
char a[1000005];
int beg[2005];
int head[2005][26];
int nxt[1000005][26];
int seq[2005];
int dp[2005][2005][2];
char s[2005];
int realhead[2005][26][2];
int n, m;
void getrealnxt(int &rx1, int &rx2, int v, int r1, int r2) {
  if (r1 == -1) return;
  if (nxt[beg[seq[r1]] + r2][v] != -1) {
    rx1 = r1;
    rx2 = nxt[beg[seq[r1]] + r2][v];
  } else if (r1 + 1 == m)
    return;
  else if (realhead[r1 + 1][v][0] == -1)
    return;
  else {
    rx1 = realhead[r1 + 1][v][0];
    rx2 = realhead[r1 + 1][v][1];
  }
}
inline void update(int *x, int r1, int r2) {
  if (r1 == -1) return;
  if (x[0] == -1) {
    x[0] = r1;
    x[1] = r2;
  } else if (x[0] > r1 || (x[0] == r1 && x[1] > r2)) {
    x[0] = r1;
    x[1] = r2;
  }
}
int main(void) {
  memset(head, -1, sizeof(head));
  memset(nxt, -1, sizeof(nxt));
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  int offset = 0;
  for (int i = 0; i < n; i++) {
    beg[i] = offset;
    scanf("%s", a + offset);
    offset += strlen(a + offset);
  }
  beg[n] = offset;
  for (int i = 0; i < n; i++) {
    for (int j = beg[i + 1] - 1; j >= beg[i]; j--) {
      int v = (a[j] - 'a');
      for (int k = 0; k < 26; k++) nxt[j][k] = head[i][k];
      head[i][v] = j - beg[i];
    }
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &seq[i]);
    --seq[i];
  }
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 26; j++) realhead[i][j][0] = realhead[i][j][1] = -1;
    for (int j = 0; j < 26; j++)
      for (int x = i; x < m; x++)
        if (head[seq[x]][j] != -1) {
          realhead[i][j][0] = x;
          realhead[i][j][1] = head[seq[x]][j];
          break;
        }
  }
  for (int i = 1; i <= len; i++) {
    int v = s[i] - 'a';
    for (int j = 0; j < i; j++)
      dp[i][j][0] = dp[i - 1][j][0], dp[i][j][1] = dp[i - 1][j][1];
    if (realhead[0][v][0] != -1) {
      update(dp[i][1], realhead[0][v][0], realhead[0][v][1]);
    }
    for (int j = 0; j < i; j++) {
      int rx1 = -1, rx2 = -1;
      getrealnxt(rx1, rx2, v, dp[i - 1][j][0], dp[i - 1][j][1]);
      update(dp[i][j + 1], rx1, rx2);
    }
  }
  int ans = 0;
  for (int i = 0; i <= len; i++)
    if (dp[len][i][0] != -1) ans = i;
  printf("%d\n", ans);
  return 0;
}
