#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2200;
const int MAXLEN = 1100000;
int n, m, l;
char s[MAXLEN];
int x[MAXN];
vector<int> p1[MAXN][26];
int p2[26][MAXN], nxt[26];
bool b[MAXN][26];
pair<int, int> f[MAXN];
pair<int, int> nextPos(pair<int, int> p, int c) {
  if (p.first > m) return make_pair(m + 1, 0);
  int u = p.first ? p1[x[p.first]][c][p.second] : -1;
  if (~u) return make_pair(p.first, u);
  int v = p2[c][p.first];
  if (~v) return make_pair(v, p1[x[v]][c][0]);
  return make_pair(m + 1, 0);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    for (int j = 0; j < 26; j++) p1[i][j].resize(len + 1);
    memset(nxt, -1, sizeof nxt);
    for (int j = len; j >= 0; j--) {
      for (int k = 0; k < 26; k++) p1[i][k][j] = nxt[k];
      if (j) nxt[s[j] - 'a'] = j, b[i][s[j] - 'a'] = 1;
    }
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d", &x[i]);
  memset(nxt, -1, sizeof nxt);
  for (int i = m; i >= 0; i--)
    for (int j = 0; j < 26; j++) {
      p2[j][i] = nxt[j];
      if (b[x[i]][j]) nxt[j] = i;
    }
  scanf("%s", s + 1);
  l = strlen(s + 1);
  for (int i = 0; i <= l; i++) f[i] = make_pair(m + 1, 0);
  f[0] = make_pair(0, 0);
  pair<int, int> tmp = nextPos(make_pair(2, 1), 0);
  for (int i = 1; i <= l; i++)
    for (int j = i; j >= 1; j--)
      f[j] = min(f[j], nextPos(f[j - 1], s[i] - 'a'));
  for (int j = l; j >= 0; j--)
    if (f[j].first <= m) {
      printf("%d\n", j);
      break;
    }
  return 0;
}
