#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
string str, b[maxn];
int n, m, a[maxn];
vector<int> pos[maxn][26];
pair<int, int> f[maxn][maxn];
int s[26][maxn];
void calcPos(const string& s, vector<int> pos[26]) {
  for (int i = 0; i < (int)s.size(); i++) pos[(int)(s[i] - 'a')].push_back(i);
}
pair<int, int> fndNext(int block, int idx, int c) {
  int it = upper_bound(pos[a[block]][c].begin(), pos[a[block]][c].end(), idx) -
           pos[a[block]][c].begin();
  if (it < (int)pos[a[block]][c].size()) {
    return make_pair(block, pos[a[block]][c][it]);
  } else {
    int l = block, r = m + 1;
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      if (s[c][mid] - s[c][block] > 0)
        r = mid;
      else
        l = mid;
    }
    if (r == m + 1) return make_pair(-1, -1);
    return make_pair(r, pos[a[r]][c][0]);
  }
}
void upd(int len, int ans, pair<int, int> z) {
  if (z.first == -1) return;
  if (f[len][ans].first == -1) {
    f[len][ans] = z;
    return;
  }
  if (z < f[len][ans]) f[len][ans] = z;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) calcPos(b[i], pos[i]);
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> a[i];
  cin >> str;
  for (int c = 0; c < 26; c++) {
    for (int i = 1; i <= m; i++) s[c][i] = s[c][i - 1] + pos[a[i]][c].size();
  }
  memset(f, 255, sizeof(f));
  f[0][0] = make_pair(0, 0);
  for (int len = 0; len < (int)str.size(); len++) {
    for (int ans = 0; ans <= (int)str.size(); ans++) {
      if (f[len][ans].first == -1) continue;
      upd(len + 1, ans + 1,
          fndNext(f[len][ans].first, f[len][ans].second, str[len] - 'a'));
      upd(len + 1, ans, f[len][ans]);
    }
  }
  for (int ans = (int)str.size(); ans >= 0; ans--) {
    if (f[(int)str.size()][ans].first != -1) {
      cout << ans << "\n";
      return 0;
    }
  }
  return 0;
}
