#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)5e3 + 7;
const int INF = (int)2e9 + 7;
int n, m;
int id[MAXN];
string s;
string a[MAXN];
int dp[MAXN][MAXN];
int nxt[MAXN][30], sum[MAXN];
vector<int> ar[MAXN][30];
int firstIn(int st, char ch) {
  int low = 0, high = m + 1;
  while (high - low > 1) {
    int mid = (low + high) >> 1;
    if (sum[mid] <= st)
      low = mid;
    else
      high = mid;
  }
  low++;
  st -= sum[low - 1];
  if (low == m + 1) return INF;
  auto it = lower_bound(ar[id[low]][ch - 'a'].begin(),
                        ar[id[low]][ch - 'a'].end(), st);
  if (it != ar[id[low]][ch - 'a'].end()) return *it + sum[low - 1];
  if (low == m) return INF;
  if (nxt[low + 1][ch - 'a'] != -1) {
    return nxt[low + 1][ch - 'a'];
  } else
    return INF;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int pos = 0; pos < a[i].size(); pos++)
      ar[i][a[i][pos] - 'a'].push_back(pos);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> id[i];
    sum[i] = sum[i - 1] + a[id[i]].size();
    for (int ch = 0; ch < 26; ch++) nxt[i][ch] = -1;
  }
  for (int i = m; i > 0; i--) {
    for (int ch = 0; ch < 26; ch++) {
      if (i < m) nxt[i][ch] = nxt[i + 1][ch];
      if (!ar[id[i]][ch].empty()) {
        nxt[i][ch] = ar[id[i]][ch][0] + sum[i - 1];
      }
    }
  }
  cin >> s;
  for (int i = 0; i <= 2000; i++)
    for (int j = 0; j <= 2000; j++) dp[i][j] = INF;
  int ans = 0;
  dp[0][0] = -1;
  dp[0][1] = firstIn(0, s[0]);
  for (int pref = 0; pref < s.size(); pref++) {
    for (int lcs = 0; lcs <= pref + 1; lcs++) {
      if (pref + 1 < s.size()) {
        dp[pref + 1][lcs] = min(dp[pref][lcs], dp[pref + 1][lcs]);
        dp[pref + 1][lcs + 1] =
            min(dp[pref + 1][lcs + 1], firstIn(dp[pref][lcs] + 1, s[pref + 1]));
      }
      if (dp[pref][lcs] != INF) ans = max(ans, lcs);
    }
  }
  cout << ans;
  return 0;
}
