#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010, INF = 2000000001;
string str[MAXN], ms;
int N, dp[MAXN][MAXN][2], order[MAXN], M;
int *nextc[MAXN][26], appear[MAXN], nextb[MAXN][26];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> str[i];
    for (int j = 0; j < 26; j++) {
      nextc[i][j] = new int[str[i].size() + 1];
      nextc[i][j][str[i].size()] = -1;
    }
    for (int j = str[i].size() - 1; j >= 0; j--) {
      for (int k = 0; k < 26; k++) nextc[i][k][j] = nextc[i][k][j + 1];
      nextc[i][str[i][j] - 'a'][j] = j;
      appear[i] |= (1 << (str[i][j] - 'a'));
    }
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> order[i];
    --order[i];
  }
  for (int i = 0; i < 26; i++) nextb[M][i] = -1;
  for (int i = M - 1; i >= 0; i--) {
    int nowb = order[i];
    for (int j = 0; j < 26; j++)
      nextb[i][j] = (appear[nowb] & (1 << j)) ? i : nextb[i + 1][j];
  }
  cin >> ms;
  for (int i = 0; i <= ms.size(); i++)
    for (int j = 0; j <= ms.size(); j++) dp[i][j][0] = dp[i][j][1] = INF;
  dp[0][0][0] = dp[0][0][1] = 0;
  for (int i = 0; i < ms.size(); i++)
    for (int j = 0; j <= i; j++)
      if (dp[i][j][0] != INF) {
        int nj = j, nextf = dp[i][j][0], nexts = dp[i][j][1],
            nowc = ms[i] - 'a';
        if (nextf < dp[i + 1][nj][0] ||
            (nextf == dp[i + 1][nj][0] && nexts < dp[i + 1][nj][1]))
          dp[i + 1][nj][0] = nextf, dp[i + 1][nj][1] = nexts;
        if (nextc[order[nextf]][nowc][nexts] != -1)
          nexts = nextc[order[nextf]][nowc][nexts] + 1;
        else if (nextb[nextf + 1][nowc] != -1)
          nextf = nextb[nextf + 1][nowc],
          nexts = nextc[order[nextf]][nowc][0] + 1;
        else
          nextf = nexts = INF;
        ++nj;
        if (nextf != INF &&
            (nextf < dp[i + 1][nj][0] ||
             (nextf == dp[i + 1][nj][0] && nexts < dp[i + 1][nj][1])))
          dp[i + 1][nj][0] = nextf, dp[i + 1][nj][1] = nexts;
      }
  for (int i = ms.size(); i >= 0; i--)
    if (dp[ms.size()][i][0] != INF) {
      printf("%d\n", i);
      break;
    }
  return 0;
}
