#include <bits/stdc++.h>
using namespace std;
const long long MXN = 5e3 + 10;
const long long INF = 1e17;
const long long SGM = 30;
int n, m, k, u, v, x, y, t, a, b, ans;
int A[MXN], T[MXN], ps[MXN];
int dp[MXN][MXN];
int nex[MXN][SGM], Sz[MXN];
string B[MXN], S;
vector<int> vec[MXN][SGM];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> B[i];
    Sz[i] = (long long)B[i].size();
    for (int j = 0; j < B[i].size(); j++) vec[i][B[i][j] - 'a'].push_back(j);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> T[i], ps[i] = ps[i - 1] + Sz[T[i]];
  for (int i = 0; i < SGM; i++) nex[m + 1][i] = m + 1;
  for (int i = m; i; i--) {
    for (int j = 0; j < SGM; j++) {
      if (vec[T[i]][j].empty())
        nex[i][j] = nex[i + 1][j];
      else
        nex[i][j] = i;
    }
  }
  cin >> S;
  n = S.size();
  for (ans = 1; ans < MXN; ans++) {
    dp[ans][0] = ps[m] + 1;
    for (int i = 1; i <= n; i++) {
      dp[ans][i] = dp[ans][i - 1];
      int pos = dp[ans - 1][i - 1], c = S[i - 1] - 'a';
      if (pos >= ps[m]) continue;
      int ind = upper_bound(ps + 1, ps + m + 1, pos) - ps;
      pos -= ps[ind - 1];
      auto tmp = lower_bound(vec[T[ind]][c].begin(), vec[T[ind]][c].end(), pos);
      if (tmp != vec[T[ind]][c].end())
        dp[ans][i] = min(dp[ans][i], ps[ind - 1] + (*tmp) + 1);
      else {
        if (ind + 1 > m) continue;
        ind = nex[ind + 1][c];
        if (ind == m + 1) continue;
        dp[ans][i] = min(dp[ans][i], ps[ind - 1] + vec[T[ind]][c][0] + 1);
      }
    }
    if (dp[ans][n] > ps[m]) break;
  }
  cout << ans - 1 << "\n";
  return 0;
}
