#include <bits/stdc++.h>
using namespace std;
int *let[2222][27];
int len[2222];
int nxt[2222][27];
char str[1111111];
pair<int, int> f[2222][2222];
int order[2222];
int n, m;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", str);
    len[i] = (int)strlen(str);
    for (int j = 0; j < 26; ++j) {
      let[i][j] = new int[len[i] + 100];
      let[i][j][len[i] - 1] = len[i];
    }
    let[i][str[len[i] - 1] - 'a'][len[i] - 1] = len[i] - 1;
    for (int j = len[i] - 2; j >= 0; --j) {
      for (int k = 0; k < 26; ++k) let[i][k][j] = let[i][k][j + 1];
      let[i][str[j] - 'a'][j] = j;
    }
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &order[i]);
    --order[i];
  }
  for (int i = 0; i < 26; ++i) nxt[m - 1][i] = m;
  for (int i = m - 2; i >= 0; --i) {
    for (int j = 0; j < 26; ++j)
      if (let[order[i + 1]][j][0] != len[order[i + 1]])
        nxt[i][j] = i + 1;
      else
        nxt[i][j] = nxt[i + 1][j];
  }
  scanf("%s", str);
  n = (int)strlen(str);
  int ans = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= i; ++j) f[i][j] = make_pair(m, 0);
  f[0][0] = make_pair(0, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (f[i][j].first == m) continue;
      f[i + 1][j] = min(f[i + 1][j], f[i][j]);
      ans = max(ans, j);
      int pos = let[order[f[i][j].first]][str[i] - 'a'][f[i][j].second];
      if (pos == len[order[f[i][j].first]]) {
        int who = nxt[f[i][j].first][str[i] - 'a'];
        if (who < m) {
          pos = let[order[who]][str[i] - 'a'][0];
          if (pos < len[order[who]] - 1)
            f[i + 1][j + 1] = min(f[i + 1][j + 1], make_pair(who, pos + 1));
          else
            f[i + 1][j + 1] = min(f[i + 1][j + 1], make_pair(who + 1, 0));
          ans = max(ans, j + 1);
        }
      } else {
        if (pos < len[order[f[i][j].first]] - 1)
          f[i + 1][j + 1] =
              min(f[i + 1][j + 1], make_pair(f[i][j].first, pos + 1));
        else
          f[i + 1][j + 1] =
              min(f[i + 1][j + 1], make_pair(f[i][j].first + 1, 0));
        ans = max(ans, j + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
