#include <bits/stdc++.h>
using namespace std;
const int MAX = 2020, oo = INT_MAX;
int n;
string ts[MAX];
int m;
int idx[MAX];
string ss;
pair<int, int> dp[MAX][MAX];
vector<int> fPos[MAX][26];
pair<int, int> suffixPos[MAX][26];
pair<int, int> shorter(const pair<int, int> &a, const pair<int, int> &b) {
  if (a == pair<int, int>(-1, -1) && b == pair<int, int>(1, -1))
    return a;
  else if (a == pair<int, int>(-1, -1))
    return b;
  else if (b == pair<int, int>(-1, -1))
    return a;
  if (a.first < b.first)
    return a;
  else if (a.first > b.first)
    return b;
  else if (a.second < b.second)
    return a;
  else if (a.second > b.second)
    return b;
  else
    return a;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ts[i];
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> idx[i];
  cin >> ss;
  for (int i = 1; i <= n; i++)
    for (int c = 0; c < 26; c++)
      fPos[i][c].resize(ts[i].size()), fPos[i][c].shrink_to_fit();
  for (int i = 1; i <= n; i++) {
    for (int c = 0; c < 26; c++) {
      for (int j = (int)ts[i].size() - 1; j >= 0; j--) {
        if (j == (int)ts[i].size() - 1) {
          if (ts[i][j] - 'a' == c)
            fPos[i][c][j] = (int)ts[i].size() - 1;
          else
            fPos[i][c][j] = -1;
        } else {
          if (ts[i][j] - 'a' == c)
            fPos[i][c][j] = j;
          else
            fPos[i][c][j] = fPos[i][c][j + 1];
        }
      }
    }
  }
  for (int suffix = m; suffix >= 1; suffix--) {
    int id = idx[suffix];
    for (int c = 0; c < 26; c++) {
      if (suffix == m) {
        if (fPos[id][c][0] == -1)
          suffixPos[suffix][c] = {-1, -1};
        else
          suffixPos[suffix][c] = {suffix, fPos[id][c][0]};
      } else {
        if (fPos[id][c][0] != -1)
          suffixPos[suffix][c] = {suffix, fPos[id][c][0]};
        else
          suffixPos[suffix][c] = suffixPos[suffix + 1][c];
      }
    }
  }
  for (int pos = 0; pos < ss.size(); pos++) {
    for (int k = 1; k <= pos + 1; k++) {
      if (pos == 0 && k == 1) {
        dp[pos][k] = suffixPos[1][ss[pos] - 'a'];
      } else if (k == 1) {
        dp[pos][k] = shorter(dp[pos - 1][k], suffixPos[1][ss[pos] - 'a']);
      } else {
        auto &ele = dp[pos][k];
        if (k <= pos)
          ele = dp[pos - 1][k];
        else
          ele = pair<int, int>(-1, -1);
        auto &p1 = dp[pos - 1][k - 1];
        if (p1.first != -1) {
          int id = idx[p1.first];
          if (p1.second == (int)ts[id].size() - 1) {
            if (p1.first != m)
              ele = shorter(ele, suffixPos[p1.first + 1][ss[pos] - 'a']);
          } else {
            int tmp = fPos[id][ss[pos] - 'a'][p1.second + 1];
            if (tmp == -1) {
              if (p1.first != m)
                ele = shorter(ele, suffixPos[p1.first + 1][ss[pos] - 'a']);
            } else
              ele = shorter(ele, pair<int, int>(p1.first, tmp));
          }
        }
      }
    }
  }
  int mx = oo;
  for (int k = ss.size(); k >= 1; k--) {
    if (dp[(int)ss.size() - 1][k].first != -1) {
      mx = k;
      break;
    }
  }
  if (mx == oo)
    printf("%d\n", 0);
  else
    printf("%d\n", mx);
  return 0;
}
