#include <bits/stdc++.h>
using namespace std;
const int BUF_MAX = 1000500;
char buf[BUF_MAX];
const int N_MAX = 2020;
const int A = 26;
struct Array {
  int a[A];
};
string s[N_MAX];
vector<Array> nxt[N_MAX];
int b[N_MAX];
char t[N_MAX];
int rndx[N_MAX];
int rpos[N_MAX];
int f[N_MAX];
Array gnext[N_MAX];
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n; ++i) {
    gets(buf);
    s[i] = string(buf);
    int len = s[i].length();
    nxt[i].resize(len + 1);
    for (int j = 0; j < A; ++j) nxt[i].back().a[j] = -1;
    for (int j = len - 1; j >= 0; --j) {
      nxt[i][j] = nxt[i][j + 1];
      int cur = s[i][j] - 'a';
      nxt[i][j].a[cur] = j;
    }
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int x;
    scanf("%d", &x);
    b[i] = x - 1;
  }
  gets(t);
  gets(t);
  int k = strlen(t);
  gnext[m - 1] = nxt[b[m - 1]][0];
  for (int j = 0; j < A; ++j)
    if (gnext[m - 1].a[j] != -1) gnext[m - 1].a[j] = m - 1;
  for (int i = m - 2; i >= 0; --i) {
    gnext[i] = gnext[i + 1];
    for (int j = 0; j < A; ++j)
      if (nxt[b[i]][0].a[j] != -1) gnext[i].a[j] = i;
  }
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    int c = t[i] - 'a';
    for (int j = i; j >= 1; --j)
      if (f[j] != 0) {
        int newndx = -1, newpos = -1;
        if (nxt[b[rndx[j]]][rpos[j]].a[c] != -1) {
          newndx = rndx[j];
          newpos = nxt[b[rndx[j]]][rpos[j]].a[c] + 1;
        } else {
          if (rndx[j] + 1 < m && gnext[rndx[j] + 1].a[c] != -1) {
            newndx = gnext[rndx[j] + 1].a[c];
            newpos = nxt[b[newndx]][0].a[c] + 1;
          }
        }
        if (newndx != -1) {
          if (f[j + 1] == 0 ||
              (f[j + 1] == 1 && make_pair(newndx, newpos) <
                                    make_pair(rndx[j + 1], rpos[j + 1]))) {
            rndx[j + 1] = newndx;
            rpos[j + 1] = newpos;
            f[j + 1] = 1;
          }
        }
      }
    if (gnext[0].a[c] != -1) {
      int newndx = gnext[0].a[c];
      int newpos = nxt[b[newndx]][0].a[c] + 1;
      if (f[1] == 0 || (f[1] == 1 && make_pair(newndx, newpos) <
                                         make_pair(rndx[1], rpos[1])))
        f[1] = 1, rndx[1] = newndx, rpos[1] = newpos;
    }
  }
  for (int i = 1; i <= k; ++i)
    if (f[i]) ans = i;
  printf("%d\n", ans);
  return 0;
}
