#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int n, m;
string base[2005];
int ptr[2005];
string s;
vector<int> each[2005][27];
int findnxt(vector<int>& a, int p) {
  return *lower_bound((a).begin(), (a).end(), p);
}
pair<int, int> dp[2005][2005];
int have[2005][26];
int findchar[2005][26];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) cin >> base[i];
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) scanf("%d", &ptr[i]), --ptr[i];
  cin >> s;
  for (int i = 0; i < n; ++i) {
    int len = base[i].size();
    for (int j = 0; j < len; ++j) each[i][base[i][j] - 'a'].push_back(j);
    for (int j = 0; j < 26; ++j) each[i][j].push_back(INF);
    for (int j = 0; j < len; ++j) have[i][base[i][j] - 'a'] = 1;
  }
  for (int i = 0; i < m; ++i)
    for (int c = 0; c < 26; ++c) {
      findchar[i][c] = m + 1;
      for (int j = i; j < m; ++j)
        if (have[ptr[j]][c]) {
          findchar[i][c] = j;
          break;
        }
    }
  int res = 0;
  for (int i = 0; i < 2005; ++i)
    for (int j = 0; j < 2005; ++j) dp[i][j] = make_pair(INF, INF);
  dp[0][0] = make_pair(0, 0);
  for (int i = 0; i < s.size() + 1; ++i)
    for (int j = 0; j < s.size() + 1; ++j)
      if (dp[i][j].first != INF) {
        res = max(res, j);
        if (i == s.size()) continue;
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        int who = dp[i][j].first, pos = dp[i][j].second;
        if (who >= m) continue;
        int p = findnxt(each[ptr[who]][s[i] - 'a'], pos);
        if (p == INF) {
          ++who;
          if (who == m) continue;
          who = findchar[who][s[i] - 'a'];
          if (who < m) {
            p = findnxt(each[ptr[who]][s[i] - 'a'], 0);
            dp[i + 1][j + 1] = min(dp[i + 1][j + 1], make_pair(who, p + 1));
          }
        } else
          dp[i + 1][j + 1] = min(dp[i + 1][j + 1], make_pair(who, p + 1));
      }
  printf("%d\n", res);
  return 0;
}
