#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30, N = 2010, M = 1001000;
int n, m, L;
int h[N], t[N], nt[M][26], a[N], NT[N][26];
pair<int, int> f[N][N], INF = make_pair(inf, inf), q;
char s[M], c[N];
pair<int, int> find(const pair<int, int> A, const int B) {
  int x, y;
  if (A.first == 0) {
    x = NT[1][B];
    y = x < inf ? nt[h[a[x]]][B] : inf;
    return make_pair(x, y);
  }
  if (t[a[A.first]] > A.second) {
    x = A.first;
    y = nt[A.second + 1][B];
    if (y == inf) {
      x = NT[A.first + 1][B];
      y = x < inf ? nt[h[a[x]]][B] : inf;
    }
    return make_pair(x, y);
  }
  x = NT[A.first + 1][B];
  y = x < inf ? nt[h[a[x]]][B] : inf;
  return make_pair(x, y);
}
int main() {
  t[0] = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    h[i] = t[i - 1] + 1, scanf("%s", s + h[i]),
    t[i] = t[i - 1] + strlen(s + h[i]);
    for (int j = 0; j <= 25; ++j) nt[t[i] + 1][j] = inf;
    for (int j = t[i]; j >= h[i]; --j) {
      for (int k = 0; k <= 25; ++k) nt[j][k] = nt[j + 1][k];
      nt[j][s[j] - 'a'] = j;
    }
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) scanf("%d", &a[i]);
  for (int i = 0; i <= 25; ++i) NT[m + 1][i] = inf;
  for (int i = m; i > 0; --i) {
    for (int j = 0; j <= 25; ++j)
      NT[i][j] = (nt[h[a[i]]][j] < inf ? i : NT[i + 1][j]);
  }
  for (int i = 0; i <= 25; ++i) NT[0][i] = NT[1][i];
  scanf("%s", c + 1);
  L = strlen(c + 1);
  f[0][0] = make_pair(0, 0);
  for (int i = 1; i <= L; ++i) f[0][i] = make_pair(inf, inf);
  int ans = 0;
  for (int i = 1; i <= L; ++i) {
    for (int j = 0; j <= L; ++j) f[i][j] = f[i - 1][j];
    for (int j = L - 1; j >= 0; --j)
      if (f[i - 1][j] != INF) {
        q = find(f[i - 1][j], c[i] - 'a');
        if (q < f[i][j + 1]) f[i][j + 1] = q;
      }
    for (int j = ans; j <= L; ++j)
      if (f[i][j] < INF) ans = j;
  }
  cout << ans << endl;
  return 0;
}
