#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 5;
const int L = 1e6 + 5;
const int inf = 0x3f3f3f3f;
template <class T>
inline void getin(T& num) {
  char c;
  bool flag = 0;
  num = 0;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = 1;
  while (c >= '0' && c <= '9') {
    num = num * 10 + c - 48;
    c = getchar();
  }
  if (flag) num = -num;
}
string base[N];
int n, m, id[N], d[N], f[N][N], nxt[L][30];
char B[N];
bool have[N][30];
vector<int> letter[N][30];
inline int getnxt(int pos, int ch) {
  int p = lower_bound(d + 1, d + m + 1, pos) - d;
  int p2 = pos - d[p - 1];
  vector<int>::iterator it =
      lower_bound(letter[id[p]][ch].begin(), letter[id[p]][ch].end(), p2);
  if (it != letter[id[p]][ch].end()) return d[p - 1] + *it;
  p = nxt[p + 1][ch];
  if (!p) return inf;
  return d[p - 1] + letter[id[p]][ch][0];
}
int main() {
  getin(n);
  for (int i = 1; i <= n; i++) {
    cin >> base[i];
    int len = base[i].size();
    for (int j = 0; j < len; j++) {
      have[i][base[i][j] - 'a' + 1] = 1;
      letter[i][base[i][j] - 'a' + 1].push_back(j + 1);
    }
  }
  getin(m);
  for (int i = 1; i <= m; i++) {
    getin(id[i]);
    d[i] = d[i - 1] + base[id[i]].size();
  }
  for (int i = m; i; i--)
    for (int j = 1; j <= 26; j++) {
      if (have[id[i]][j])
        nxt[i][j] = i;
      else
        nxt[i][j] = nxt[i + 1][j];
    }
  scanf("%s", B + 1);
  int b = strlen(B + 1);
  memset(f, 0x3f, sizeof f);
  for (int i = 0; i <= b; i++) f[i][0] = 0;
  for (int i = 0; i < b; i++)
    for (int j = 0; j <= i; j++)
      if (f[i][j] < inf) {
        f[i + 1][j] = min(f[i + 1][j], f[i][j]);
        f[i + 1][j + 1] =
            min(f[i + 1][j + 1], getnxt(f[i][j] + 1, B[i + 1] - 'a' + 1));
      }
  for (int i = b; i >= 0; i--)
    if (f[b][i] <= d[m]) printf("%d\n", i), exit(0);
}
