#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643l;
string s[2010];
int qwert[26000010];
int *nx[2010];
string t;
int q[2010];
int lt[26];
int nx1[2010][26];
pair<int, int> d[2010][2010];
int main() {
  memset(qwert, -1, sizeof qwert);
  int n;
  cin >> n;
  getline(cin, t);
  int NX = 0;
  for (int i = 0; i < int(n); i++) {
    nx[i] = qwert + NX;
    getline(cin, s[i]);
    for (int j = 0; j < int(s[i].size()); j++) {
      s[i][j] -= 'a';
    }
    for (int j = 0; j < int(26); j++) {
      lt[j] = 1000000000;
    }
    for (int j = int(s[i].size()) - 1; j >= 0; j--) {
      lt[s[i][j]] = j;
      memcpy(qwert + NX + j * 26, lt, 26 * sizeof(int));
    }
    NX += s[i].size() * 26;
  }
  int m;
  cin >> m;
  for (int i = 0; i < int(m); i++) {
    cin >> q[i];
    q[i]--;
  }
  getline(cin, t);
  getline(cin, t);
  for (int j = 0; j < int(t.size()); j++) {
    t[j] -= 'a';
  }
  for (int j = 0; j < int(26); j++) {
    lt[j] = 1000000000;
  }
  for (int j = int(m) - 1; j >= 0; j--) {
    for (int k = 0; k < int(26); k++) {
      if (nx[q[j]][k] < 1000000000) {
        lt[k] = j;
      }
      memcpy(nx1[j], lt, 26 * sizeof(int));
    }
  }
  for (int i = 0; i < int(2010); i++) {
    for (int j = 0; j < int(2010); j++) {
      d[i][j] = make_pair(1000000000, 1000000000);
    }
  }
  d[0][0] = make_pair(0, 0);
  for (int i = 0; i < int(t.size()); i++) {
    for (int j = 0; j < int(i + 1); j++) {
      if (d[i][j] != make_pair(1000000000, 1000000000)) {
        d[i + 1][j] = min(d[i + 1][j], d[i][j]);
        int x = d[i][j].first, y = d[i][j].second;
        if (x == m) {
          continue;
        }
        y = nx[q[x]][26 * y + t[i]];
        if (y == 1000000000) {
          y = 0;
          x++;
          if (x == m) {
            continue;
          }
          x = nx1[x][t[i]];
          if (x == 1000000000) {
            continue;
          }
          y = nx[q[x]][t[i]];
        }
        y++;
        if (y == s[q[x]].size()) {
          x++;
          y = 0;
        }
        d[i + 1][j + 1] = min(d[i + 1][j + 1], make_pair(x, y));
      }
    }
  }
  int h = 0;
  while (d[t.size()][h + 1] != make_pair(1000000000, 1000000000)) {
    h++;
  }
  cout << h;
  return 0;
}
