#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const int N = 2e3 + 7;
vector<int> plc[N][30], in[30];
int n, m;
bool has[N][30];
int knd[N], ps[N], sz[N];
pair<int, int> dp[N][N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    sz[i] = s.size();
    for (int j = 1; j <= s.size(); j++) {
      int c = s[j - 1] - 'a';
      has[i][c] = 1;
      plc[i][c].push_back(j);
    }
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> knd[i];
    for (int j = 0; j < 26; j++)
      if (has[knd[i]][j]) in[j].push_back(i);
  }
  string s;
  cin >> s;
  int k = s.size();
  for (int j = 1; j <= k; j++) dp[0][j] = {2001, 2e9 + 7};
  for (int i = 1; i <= s.size(); i++) {
    int c = s[i - 1] - 'a';
    for (int j = 1; j <= i; j++) {
      dp[i][j] = dp[i - 1][j];
      int pk = dp[i - 1][j - 1].first;
      int p = dp[i - 1][j - 1].second;
      bool ok = 0;
      if (pk != 0) {
        int t = upper_bound(plc[knd[pk]][c].begin(), plc[knd[pk]][c].end(), p) -
                plc[knd[pk]][c].begin();
        if (t != plc[knd[pk]][c].size()) {
          ok = 1;
          if (pk < dp[i][j].first ||
              (pk == dp[i][j].first && plc[knd[pk]][c][t] < dp[i][j].second))
            dp[i][j] = {pk, plc[knd[pk]][c][t]};
        }
      }
      if (!ok) {
        int t = upper_bound(in[c].begin(), in[c].end(), pk) - in[c].begin();
        if (t != in[c].size()) {
          int npk = in[c][t];
          if (npk < dp[i][j].first ||
              (npk == dp[i][j].first && plc[knd[npk]][c][0] < dp[i][j].second))
            dp[i][j] = {npk, plc[knd[npk]][c][0]};
        }
      }
    }
    for (int j = i + 1; j <= k; j++) dp[i][j] = {2001, 2e9 + 7};
  }
  for (int j = k; j >= 0; j--)
    if (dp[k][j].first != 2001) {
      cout << j;
      return 0;
    }
}
