#include <bits/stdc++.h>
using namespace std;
const int N = 2050, LEN = int(1e6) + 5, inf = ~0u >> 1;
struct next_t {
  int n[26];
  int &operator[](int x) { return n[x]; }
};
struct string_counter_t {
  vector<char> S;
  int len;
  vector<next_t> cnext;
  void bind(char *s) {
    len = strlen(s + 1);
    S.resize(len + 5);
    copy(s + 1, s + 1 + len, ++S.begin());
    cnext.resize(len + 5);
    for (int i = (0), IE = (25); i <= IE; ++i) cnext[len][i] = inf;
    for (int i = (len - 1), IE = (0); i >= IE; --i) {
      for (int c = (0), IE = (25); c <= IE; ++c) cnext[i][c] = cnext[i + 1][c];
      cnext[i][S[i + 1] - 'a'] = i + 1;
    }
  }
  int query(int x, char c) { return cnext[x][c - 'a']; }
} S[N];
int n_str, n_arr;
struct array_t {
  pair<int, int> cnext[N][26];
  int id[N];
  void init() {
    for (int i = (0), IE = (25); i <= IE; ++i)
      cnext[n_arr][i] = pair<int, int>(inf, inf);
    for (int i = (n_arr - 1), IE = (0); i >= IE; --i)
      for (int c = (0), IE = (25); c <= IE; ++c)
        if (S[id[i + 1]].cnext[0][c] != inf)
          cnext[i][c] = pair<int, int>(i + 1, S[id[i + 1]].cnext[0][c]);
        else
          cnext[i][c] = cnext[i + 1][c];
  }
  pair<int, int> query(pair<int, int> x, char c) {
    int z = S[id[x.first]].query(x.second, c);
    if (z != inf)
      return pair<int, int>(x.first, z);
    else
      return cnext[x.first][c - 'a'];
  }
} ARR;
struct dp_t {
  char S[N];
  int len;
  pair<int, int> minpos[N];
  int solve() {
    fill(minpos, minpos + 1 + len + 1, pair<int, int>(inf, inf));
    minpos[0] = pair<int, int>(1, 0);
    for (int i = 1; i <= len; ++i)
      for (int j = len - 1; j >= 0; --j)
        if (minpos[j].first != inf)
          minpos[j + 1] = min(minpos[j + 1], ARR.query(minpos[j], S[i]));
    int res = len + 1;
    for (; minpos[res].first == inf; --res)
      ;
    return res;
  }
  void bind(char *s) {
    len = strlen(s + 1);
    copy(s + 1, s + 1 + len, S + 1);
  }
} DP;
struct parser_t {
  void solve() {
    static char tmp[LEN];
    scanf("%d", &::n_str);
    for (int i = 1; i <= n_str; ++i) {
      scanf("%s", tmp + 1);
      S[i].bind(tmp);
    }
    scanf("%d", &::n_arr);
    for (int i = 1; i <= n_arr; ++i) scanf("%d", &ARR.id[i]);
    ARR.init();
    scanf("%s", tmp + 1);
    DP.bind(tmp);
    int r = DP.solve();
    printf("%d\n", r);
  }
} P;
int main() {
  P.solve();
  return 0;
}
