#include <bits/stdc++.h>
using namespace std;
char B[2005], base[1000005];
int n, m, k, st[2005], sw[2005], id[2005];
int nxt[1000005][30], txt[2005][30];
int f[2005][2005], ans;
int mind(int s, char key) {
  if (s >= sw[m + 1]) return 0x7f7f7f7f;
  int p = upper_bound(sw + 1, sw + m + 1, s) - sw - 1;
  int w = st[id[p]] + s - sw[p];
  if (nxt[w][key - 'a'] != -1) return s + (nxt[w][key - 'a'] - w);
  if (txt[p][key - 'a']) {
    int p2 = id[txt[p][key - 'a']];
    return nxt[st[p2]][key - 'a'] - st[p2] + sw[txt[p][key - 'a']];
  }
  return 0x7f7f7f7f;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", base + st[i]);
    for (st[i + 1] = st[i]; base[st[i + 1]]; st[i + 1]++)
      ;
  }
  int p = n + 1;
  memset(nxt, -1, sizeof(nxt));
  for (int i = st[n + 1] - 1; i >= 0; i--) {
    if (i + 1 == st[p])
      p--;
    else
      memcpy(nxt[i], nxt[i + 1], sizeof(nxt[i]));
    nxt[i][base[i] - 'a'] = i;
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d\n", &id[i]);
    sw[i + 1] = sw[i] + st[id[i] + 1] - st[id[i]];
  }
  for (int i = m - 1; i >= 1; i--) {
    memcpy(txt[i], txt[i + 1], sizeof(txt[i]));
    for (int j = 0; j < 26; j++)
      if (nxt[st[id[i + 1]]][j] != -1) txt[i][j] = i + 1;
  }
  scanf("%s", B + 1);
  k = strlen(B + 1);
  memset(f, 0x7f, sizeof(f));
  f[0][0] = -1;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= i; j++) {
      f[i][j] = f[i - 1][j];
      if (j == 4) j += 0;
      if (j) f[i][j] = min(f[i][j], mind(f[i - 1][j - 1] + 1, B[i]));
      if (f[i][j] < 0x7f7f7f7f) ans = max(ans, j);
    }
  }
  printf("%d\n", ans);
}
