#include <bits/stdc++.h>
using namespace std;
const int MAXL = 1000010;
const int MAXN = 2048;
const int MAXK = 26;
const int INF = 0x3f3f3f3f;
char buf[MAXL];
vector<string> vec;
vector<int> dp1[MAXN][MAXK];
int last[MAXK];
int dp2[MAXN][MAXK];
int n, m, l, br[MAXN];
pair<int, int> dp[MAXN][MAXN];
void init() {}
void input() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", buf);
    vec.push_back(buf);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &br[i]);
    --br[i];
  }
  scanf("%s", buf);
}
void output() {}
pair<int, int> getNxt(pair<int, int> cur, int id) {
  int p = lower_bound(dp1[br[cur.first]][id].begin(),
                      dp1[br[cur.first]][id].end(), cur.second + 1) -
          dp1[br[cur.first]][id].begin();
  if (p == dp1[br[cur.first]][id].size()) {
    cur.first = dp2[cur.first][id];
    if (cur.first != INF) cur.second = dp1[br[cur.first]][id][0];
  } else {
    cur.second = dp1[br[cur.first]][id][p];
  }
  return cur;
}
void solved() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < vec[i].size(); ++j) {
      dp1[i][vec[i][j] - 'a'].push_back(j);
    }
  }
  memset(dp2, INF, sizeof(dp2));
  memset(last, INF, sizeof(last));
  for (int i = m - 1; i >= 0; --i) {
    for (int j = 0; j < MAXK; ++j) {
      dp2[i][j] = last[j];
      if (dp1[br[i]][j].size() > 0) {
        last[j] = i;
      }
    }
  }
  l = strlen(buf);
  memset(dp, INF, sizeof(dp));
  dp[0][0] = make_pair(0, -1);
  int ans = 0;
  for (int len = 0; len <= l; ++len) {
    for (int i = 0; i < l; ++i) {
      dp[len][i + 1] = min(dp[len][i + 1], dp[len][i]);
    }
    if (dp[len][l].first == INF) break;
    ans = len;
    for (int i = 0; i < l; ++i) {
      int id = buf[i] - 'a';
      if (dp[len][i].first != INF) {
        pair<int, int> nxt = getNxt(dp[len][i], id);
        if (nxt.first != INF) {
          dp[len + 1][i + 1] = min(dp[len + 1][i + 1], nxt);
        }
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  init();
  input();
  solved();
  output();
  return 0;
}
