#include <bits/stdc++.h>
using namespace std;
char buffer[2000000], *buf = buffer;
typedef int NEXTC[26];
NEXTC bufnext[1000010], *bnext = bufnext;
const int max_n = 2050;
struct String {
  char* s;
  int len;
  NEXTC* next;
  void scan() {
    scanf("%s", buf);
    s = buf;
    len = int(strlen(buf));
    buf += len + 1;
    next = bnext;
    bnext += len;
    for (int i = 0; i < 26; i++) {
      next[len - 1][i] = -1;
    }
    next[len - 1][s[len - 1] - 'a'] = len - 1;
    for (int i = len - 2; i >= 0; i--) {
      memcpy(next[i], next[i + 1], sizeof(next[i]));
      next[i][s[i] - 'a'] = i;
    }
  }
} a[max_n];
struct FNext {
  int i;
  int p;
  FNext() {
    i = 1000000000;
    p = -1;
  }
  void init(int i, int p) {
    this->i = i;
    this->p = p;
  }
  bool operator<(const FNext& f) const {
    return i < f.i || i == f.i && p < f.p;
  }
} fnext[max_n][26], dp[max_n][max_n], t;
typedef String* PString;
PString b[max_n];
char s[max_n];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    a[i].scan();
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int t;
    scanf("%d", &t);
    b[i] = &a[t - 1];
  }
  int mem = sizeof(fnext[0]);
  for (int i = m - 2; i >= 0; i--) {
    memcpy(fnext[i], fnext[i + 1], mem);
    for (int j = 0; j < 26; j++) {
      int p = b[i + 1]->next[0][j];
      if (p != -1) {
        fnext[i][j].init(i + 1, p);
      }
    }
  }
  scanf("%s", &s);
  dp[0][0].init(0, 0);
  n = int(strlen(s));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (dp[i][j].p == -1) {
        continue;
      }
      if (dp[i][j] < dp[i + 1][j]) {
        dp[i + 1][j] = dp[i][j];
      }
      if (dp[i][j].i == m) {
        continue;
      }
      int id = dp[i][j].i, pos = dp[i][j].p;
      int npos = b[id]->next[pos][s[i] - 'a'], nid = id;
      if (npos != -1) {
        npos++;
        if (b[id]->len == npos) {
          npos = 0;
          nid++;
        }
        t.init(nid, npos);
        if (t < dp[i + 1][j + 1]) {
          dp[i + 1][j + 1] = t;
        }
      } else {
        t = fnext[id][s[i] - 'a'];
        if (t.p != -1) {
          t.p++;
          if (b[t.i]->len == t.p) {
            t.i++;
            t.p = 0;
          }
          if (t < dp[i + 1][j + 1]) {
            dp[i + 1][j + 1] = t;
          }
        }
      }
    }
  }
  for (int j = n; j >= 0; j--) {
    if (dp[n][j].p != -1) {
      printf("%d\n", j);
      break;
    }
  }
  return 0;
}
