#include <bits/stdc++.h>
#pragma comment(linker, "/stack:256000000")
using namespace std;
const int N = 2010, K = 26;
vector<int> dp1[N][K];
int dp2[K][N];
pair<int, int> dp[N][N];
int main() {
  int n;
  cin >> n;
  for (int(i) = 0; (i) < (n); (i)++) {
    string s;
    cin >> s;
    for (int(j) = 0; (j) < (26); (j)++) {
      dp1[i][j].assign((int)(s).size(), -1);
      for (int k = (int)(s).size() - 1; k >= 0; k--) {
        if (k + 1 < (int)(s).size()) dp1[i][j][k] = dp1[i][j][k + 1];
        if (s[k] == (char)('a' + j)) {
          dp1[i][j][k] = k;
        }
      }
    }
  }
  int m;
  cin >> m;
  vector<int> id(m);
  for (int(i) = 0; (i) < (m); (i)++) {
    cin >> id[i];
    id[i]--;
  }
  memset(dp2, -1, sizeof(dp2));
  for (int(i) = 0; (i) < (26); (i)++) {
    for (int j = m - 1; j >= 0; j--) {
      if (j + 1 < m) {
        dp2[i][j] = dp2[i][j + 1];
      }
      if (dp1[id[j]][i][0] != -1) {
        dp2[i][j] = j;
      }
    }
  }
  string s;
  cin >> s;
  for (int(i) = 0; (i) < ((int)(s).size() + 1); (i)++)
    for (int(j) = 0; (j) < ((int)(s).size() + 1); (j)++)
      dp[i][j] = make_pair(N, N);
  dp[0][0] = make_pair(0, -1);
  for (int i = 1; i <= (int)(s).size(); i++) {
    for (int j = 0; j <= (int)(s).size(); j++) {
      dp[i][j] = dp[i - 1][j];
      if (j > 0) {
        pair<int, int> pos = dp[i - 1][j - 1];
        if (pos.first != N) {
          int c = s[i - 1] - 'a';
          if (pos.second + 1 < dp1[id[pos.first]][c].size() &&
              dp1[id[pos.first]][c][pos.second + 1] != -1) {
            dp[i][j] = min(
                dp[i][j],
                make_pair(pos.first, dp1[id[pos.first]][c][pos.second + 1]));
          } else if (pos.first + 1 < m) {
            int t = dp2[c][pos.first + 1];
            if (t != -1) {
              int x = dp1[id[t]][c][0];
              dp[i][j] = min(dp[i][j], make_pair(t, x));
            }
          }
        }
      }
    }
  }
  int res = 0;
  for (int(i) = 0; (i) < ((int)(s).size() + 1); (i)++) {
    for (int(j) = 0; (j) < ((int)(s).size() + 1); (j)++) {
      if (dp[i][j].first != N) {
        res = max(res, j);
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
