#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long llread() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
pair<int, int> Next[2010][26];
int nxt[1000010][26];
string str[2010];
int id[2010], sum[2010];
int head[26];
pair<int, int> f[2010][2010];
inline pair<int, int> calculate(pair<int, int> now, int latin) {
  bool flag = false;
  if (now.first == 1 && now.first == 1) flag = true;
  if (now.first == 2147483647 || now.second == 2147483647)
    return make_pair(2147483647, 2147483647);
  pair<int, int> ret = make_pair(now.first, 0);
  if (now.second != str[id[now.first]].size()) {
    int t = nxt[sum[id[now.first] - 1] + now.second + 1][latin];
    if (t != -1)
      ret.second = t;
    else
      ret = Next[now.first + 1][latin];
  } else
    ret = Next[now.first + 1][latin];
  if (ret.first == -1 || ret.second == -1)
    ret = make_pair(2147483647, 2147483647);
  return ret;
}
inline void solve() {
  string st;
  cin >> st;
  int len = st.size();
  for (int i = (0); i < (2010); i++)
    for (int j = (0); j < (2010); j++)
      f[i][j] = make_pair(2147483647, 2147483647);
  f[0][0] = make_pair(0, 0);
  int ans = 0;
  for (int i = (1); i <= (len); i++) {
    for (int j = (0); j <= (i); j++) {
      if (j)
        f[i][j] = min(f[i - 1][j], calculate(f[i - 1][j - 1], st[i - 1] - 'a'));
      else
        f[i][j] = f[i - 1][j];
      if (f[i][j] != f[2005][2005]) ans = max(ans, j);
    }
  }
  cout << ans << endl;
  return;
}
int main() {
  int n = read();
  for (int i = (1); i <= (n); i++) cin >> str[i];
  int m = read();
  for (int i = (1); i <= (m); i++) id[i] = read();
  memset(nxt, -1, sizeof(nxt));
  for (int i = (0); i < (2010); i++)
    for (int j = (0); j < (26); j++) Next[i][j] = make_pair(-1, -1);
  for (int i = (1); i <= (n); i++) {
    sum[i] = sum[i - 1] + str[i].size();
    memset(head, 0, sizeof(head));
    for (int j = (0); j < (str[i].size()); j++) {
      if (!head[str[i][j] - 'a']) head[str[i][j] - 'a'] = sum[i - 1];
      for (int kt = (head[str[i][j] - 'a'] + 1); kt <= (sum[i - 1] + j + 1);
           kt++) {
        nxt[kt][str[i][j] - 'a'] = j + 1;
      }
      head[str[i][j] - 'a'] = sum[i - 1] + j + 1;
    }
  }
  for (int i = (m); i >= (1); i--) {
    for (int j = (0); j <= (25); j++) {
      if (nxt[sum[id[i] - 1] + 1][j] != -1)
        Next[i][j] = make_pair(i, nxt[sum[id[i] - 1] + 1][j]);
      else
        Next[i][j] = Next[i + 1][j];
    }
  }
  solve();
  return 0;
}
