#include <bits/stdc++.h>
using namespace std;
void sc(char& c) {
  char temp[4];
  scanf("%s", temp);
  c = temp[0];
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
void debugarr(int* arr, int n) {
  cout << "[";
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "]" << endl;
}
int testnum;
int n;
vector<int> pos[2000][26];
char temp[1000005];
int m;
int ind[2000];
int nxt[26][2000];
char str[2005];
int len;
pair<int, int> dp[2005];
void solve() {
  for (int i = 0; i < 26; i++)
    for (int j = m - 1; j >= 0; j--) {
      if (j == m - 1)
        nxt[i][j] = m;
      else {
        if (pos[ind[j + 1]][i].size() > 0)
          nxt[i][j] = j + 1;
        else
          nxt[i][j] = nxt[i][j + 1];
      }
    }
  for (int i = 0; i <= 2000; i++) dp[i] = make_pair(-1, -1);
  dp[0] = make_pair(0, -1);
  for (int i = 0; i < len; i++) {
    int z = str[i] - 'a';
    for (int j = i; j >= 0; j--) {
      int index = dp[j].first;
      int curpos = dp[j].second;
      if (index < 0) continue;
      int curstr = ind[index];
      vector<int>::iterator it =
          upper_bound(pos[curstr][z].begin(), pos[curstr][z].end(), curpos);
      if (it == pos[curstr][z].end()) {
        int nxtstr = nxt[z][index];
        if (nxtstr != m) {
          int firstpos = pos[ind[nxtstr]][z][0];
          if (dp[j + 1].first < 0 || make_pair(nxtstr, firstpos) < dp[j + 1])
            dp[j + 1] = make_pair(nxtstr, firstpos);
        }
      } else {
        int nextpos = *it;
        if (dp[j + 1].first < 0 || make_pair(index, nextpos) < dp[j + 1])
          dp[j + 1] = make_pair(index, nextpos);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= len; i++)
    if (dp[i].first >= 0) ans = max(ans, i);
  printf("%d\n", ans);
}
bool input() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", temp);
    int k = strlen(temp);
    for (int j = 0; j < k; j++) {
      int z = temp[j] - 'a';
      pos[i][z].push_back(j);
    }
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &ind[i]);
    ind[i]--;
  }
  scanf("%s", str);
  len = strlen(str);
  return true;
}
int main() {
  int T = 1;
  for (testnum = 1; testnum <= T; testnum++) {
    if (!input()) break;
    solve();
  }
}
