#include <bits/stdc++.h>
using namespace std;
const int N = 2010, Z = 26;
int n, m, p[N], sz[N];
string s[N], t;
vector<int> pos[N][Z];
pair<int, int> dp[N][N], nxt[N][Z];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  cin >> m;
  for (int j = 1; j <= m; j++) cin >> p[j];
  cin >> t;
  for (int i = 1; i <= n; i++) {
    sz[i] = (int)(s[i].size());
    for (int j = 0; j < sz[i]; j++) pos[i][s[i][j] - 'a'].push_back(j);
  }
  for (int i = m; i >= 1; i--)
    for (int j = 0; j < Z; j++) {
      nxt[i][j] = nxt[i + 1][j];
      if (!pos[p[i]][j].empty()) nxt[i][j] = {i, pos[p[i]][j][0]};
    }
  for (int i = 0; i < N; i++)
    for (int j = 1; j < N; j++) dp[i][j] = {N - 1, N - 1};
  int tz = (int)(t.size());
  for (int i = 1; i <= tz; i++)
    for (int j = 1; j <= i; j++) {
      dp[i][j] = dp[i - 1][j];
      pair<int, int> tmp = dp[i - 1][j - 1];
      auto it =
          upper_bound(pos[p[tmp.first]][t[i - 1] - 'a'].begin(),
                      pos[p[tmp.first]][t[i - 1] - 'a'].end(), tmp.second);
      if (it != pos[p[tmp.first]][t[i - 1] - 'a'].end())
        dp[i][j] = min(dp[i][j], {tmp.first, *it});
      else if (nxt[tmp.first + 1][t[i - 1] - 'a'].first != 0) {
        pair<int, int> tt = nxt[tmp.first + 1][t[i - 1] - 'a'];
        if (tt < dp[i][j]) dp[i][j] = tt;
      }
    }
  int ans = 0;
  for (int i = 0; i <= tz; i++)
    if (dp[tz][i].first <= m) ans = i;
  cout << ans << '\n';
  return 0;
}
