#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
const int MAXLEN = 1000000;
const int INF = 0x3f3f3f3f;
template <class T>
void Read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = 0;
  while (c < '0' || '9' < c) {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (flag) x = -x;
}
char str[MAXLEN + 10];
char A[MAXN + 10];
int pos[MAXN + 10], len[MAXN + 10];
int last[MAXLEN + 10][26];
int nxt[MAXN + 10][26];
int id[MAXN + 10], sum[MAXN + 10];
int dp[MAXN + 10][MAXN + 10];
int n, m;
int main() {
  Read(n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    len[i] = strlen(str + 1);
    pos[i] = pos[i - 1] + len[i - 1];
    for (int j = len[i]; j >= 1; --j) {
      for (int k = 0; k < 26; ++k)
        last[pos[i] + j][k] = last[pos[i] + j + 1][k];
      last[pos[i] + j][str[j] - 'a'] = j;
    }
  }
  Read(m);
  for (int i = 1; i <= m; ++i) Read(id[i]), sum[i] = sum[i - 1] + len[id[i]];
  for (int i = m; i >= 1; --i) {
    for (int j = 0; j < 26; ++j) nxt[i][j] = nxt[i + 1][j];
    for (int j = 0; j < 26; ++j)
      if (last[pos[id[i]] + 1][j]) nxt[i][j] = i;
  }
  scanf("%s", str + 1);
  int tlen = strlen(str + 1);
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i <= tlen; ++i) dp[i][0] = 0;
  for (int i = 1; i <= tlen; ++i) {
    for (int j = 1; j <= i; ++j) {
      if (dp[i - 1][j - 1] < INF) {
        int k = dp[i - 1][j - 1];
        int p = lower_bound(sum + 1, sum + m + 1, k) - sum;
        int t = k - sum[p - 1];
        if (t < len[id[p]] && last[pos[id[p]] + t + 1][str[i] - 'a'])
          dp[i][j] = sum[p - 1] + last[pos[id[p]] + t + 1][str[i] - 'a'];
        else if (nxt[p + 1][str[i] - 'a']) {
          int tp = nxt[p + 1][str[i] - 'a'];
          dp[i][j] = sum[tp - 1] + last[pos[id[tp]] + 1][str[i] - 'a'];
        } else
          dp[i][j] = INF;
      }
      dp[i][j] = min(dp[i][j], dp[i - 1][j]);
    }
  }
  int ans = 0;
  for (int i = tlen; i >= 0; --i)
    if (dp[tlen][i] < INF) {
      ans = i;
      break;
    }
  printf("%d\n", ans);
}
