#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void next_int(T &x) {
  x = 0;
  char c;
  bool neg = false;
  while (!isdigit(c = getchar()))
    if (c == '-') neg = true;
  do x = x * 10 + c - 48;
  while (isdigit(c = getchar()));
  if (neg) x = -x;
}
template <typename T>
inline void write_int(T x, char last = 0) {
  if (x < 0) putchar('-'), x = abs(x);
  char tmp[20];
  int cnt = 0;
  while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10;
  tmp[cnt] = x + 48;
  for (int i = (cnt); i >= (0); --i) putchar(tmp[i]);
  if (last) putchar(last);
}
inline void read_string(char s[]) {
  int cnt = 0;
  char ch = getchar();
  while (!(ch >= 'a' && ch <= 'z')) ch = getchar();
  while (ch >= 'a' && ch <= 'z') s[++cnt] = ch, ch = getchar();
  s[cnt + 1] = '\0';
}
const int N = (int)1e6 + 5;
int n, m, b[2005], sum[2005], dp[2005][2005], nxt2[2005][26];
char a[2005];
vector<vector<int> > base;
vector<vector<int> > nxt[2005];
int main() {
  next_int(n);
  base.resize(n + 1);
  for (int i = (1); i <= (n); ++i) {
    base[i].push_back(0);
    char ch = getchar();
    while (!(ch >= 'a' && ch <= 'z')) ch = getchar();
    while (ch >= 'a' && ch <= 'z') base[i].push_back(ch - 'a'), ch = getchar();
    nxt[i].resize(((int)base[i].size()) + 2);
    for (int j = (0); j < (((int)base[i].size()) + 2); ++j)
      nxt[i][j].resize(26);
    for (int j = (0); j < (26); ++j) {
      nxt[i][((int)base[i].size())][j] = ((int)base[i].size());
      for (int k = (((int)base[i].size()) - 1); k >= (1); --k)
        nxt[i][k][j] = (base[i][k] == j ? k : nxt[i][k + 1][j]);
    }
  }
  next_int(m);
  for (int i = (1); i <= (m); ++i)
    next_int(b[i]), sum[i] = sum[i - 1] + ((int)base[b[i]].size()) - 1;
  read_string(a);
  n = strlen(a + 1);
  for (int j = (0); j < (26); ++j) nxt2[m + 1][j] = m + 1;
  for (int i = (m); i >= (1); --i)
    for (int j = (0); j < (26); ++j) {
      if (nxt[b[i]][1][j] < ((int)base[b[i]].size()))
        nxt2[i][j] = i;
      else
        nxt2[i][j] = nxt2[i + 1][j];
    }
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n + 1); ++j)
      if (dp[i][j] != -1) {
        if (dp[i + 1][j] == -1 || dp[i + 1][j] > dp[i][j])
          dp[i + 1][j] = dp[i][j];
        if (j < n) {
          int val = dp[i][j], nxt_val = 0;
          if (val == 0) {
            int tmp = nxt2[1][a[i + 1] - 'a'];
            if (tmp > m) continue;
            nxt_val = nxt[b[tmp]][1][a[i + 1] - 'a'] + sum[tmp - 1];
          } else {
            int lo = 1, hi = m, ans = 1, mid;
            while (lo <= hi) {
              mid = (lo + hi) >> 1;
              if (sum[mid] >= val)
                ans = mid, hi = mid - 1;
              else
                lo = mid + 1;
            }
            int idx = val - sum[ans - 1];
            nxt_val = nxt[b[ans]][idx + 1][a[i + 1] - 'a'];
            if (nxt_val >= ((int)base[b[ans]].size())) {
              ans = nxt2[ans + 1][a[i + 1] - 'a'];
              if (ans > m) continue;
              nxt_val = nxt[b[ans]][1][a[i + 1] - 'a'];
            }
            nxt_val += sum[ans - 1];
          }
          if (dp[i + 1][j + 1] == -1 || dp[i + 1][j + 1] > nxt_val)
            dp[i + 1][j + 1] = nxt_val;
        }
      }
  int res = 0;
  for (int i = (n); i >= (1); --i)
    if (dp[n][i] != -1) {
      res = i;
      break;
    }
  write_int(res);
  return 0;
}
