#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
string b[2001];
int h[2002];
vector<int> g[2002][26];
int f[2002][26];
string s;
int dp1[2002][26];
int id[2002];
int dp[2002][2002];
int nx(int len, char c, const int &k) {
  if (len == inf) return inf;
  int ans;
  if (len == 0) {
    ans = dp1[1][c - 'a'];
    if (ans == inf) return inf;
    return f[id[ans]][c - 'a'] + h[ans - 1] + 1;
  }
  int l = 1, r = k;
  while (l != r) {
    int m = ((l + r) >> 1);
    if (h[m] < len)
      l = m + 1;
    else
      r = m;
  }
  int t = id[r];
  if (g[t][c - 'a'][len - h[r - 1]] != inf)
    return g[t][c - 'a'][len - h[r - 1]] + h[r - 1] + 1;
  t = dp1[r + 1][c - 'a'];
  if (t == inf) return inf;
  return f[id[t]][c - 'a'] + h[t - 1] + 1;
}
int main() {
  int n;
  scanf("%d\n", &n);
  for (int i = 1; i <= n; ++i) {
    getline(cin, b[i]);
    for (int j = 0; j <= 25; ++j) f[i][j] = -1;
    for (int j = 0; j <= int((b[i]).size()) - 1; ++j)
      if (f[i][b[i][j] - 'a'] == -1) f[i][b[i][j] - 'a'] = j;
    for (int j = 0; j <= 25; ++j) g[i][j].resize(int((b[i]).size()) + 1);
    for (int j = 0; j <= 25; ++j) g[i][j][int((b[i]).size())] = inf;
    for (int c = int((b[i]).size()) - 1; c >= 0; c--) {
      for (int j = 0; j <= 25; ++j) g[i][j][c] = g[i][j][c + 1];
      g[i][b[i][c] - 'a'][c] = c;
    }
  }
  h[0] = 0;
  int k;
  scanf("%d\n", &k);
  for (int i = 1; i <= k; ++i)
    cin >> id[i], h[i] = h[i - 1] + int((b[id[i]]).size());
  scanf("\n");
  getline(cin, s);
  s = " " + s;
  for (int i = 0; i <= 25; ++i) dp1[k + 1][i] = inf;
  for (int i = k; i >= 1; i--)
    for (int j = 0; j <= 25; ++j) {
      if (f[id[i]][j] != -1)
        dp1[i][j] = i;
      else
        dp1[i][j] = dp1[i + 1][j];
    }
  for (int i = 0; i <= int((s).size()) - 1; ++i)
    for (int j = 0; j <= int((s).size()) - 1; ++j) {
      if (i < j) {
        dp[i][j] = inf;
        continue;
      }
      if (j == 0) {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = dp[i - 1][j];
      if (dp[i - 1][j - 1] != inf) {
        dp[i][j] = min(dp[i][j], nx(dp[i - 1][j - 1], s[i], k));
      }
    }
  int ans = 0;
  for (int i = 1; i <= int((s).size()) - 1; ++i)
    if (dp[int((s).size()) - 1][i] <= h[k]) ans = i;
  cout << ans << endl;
  return 0;
}
