#include <bits/stdc++.h>
using namespace std;
const int N = 2005, M = 1e6 + 5;
int n, m;
vector<int> next1[N][27];
int next2[N][27], last[30], a[N], sum[N], f[N][N];
char buf[M];
string str[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", buf);
    str[i] = buf;
  }
  for (int i = 0; i < n; ++i) {
    memset(last, -1, sizeof last);
    int len = str[i].length();
    for (int j = 0; j < 26; ++j) next1[i][j].resize(len + 1);
    for (int j = len; j >= 0; --j) {
      for (int k = 0; k < 26; ++k) next1[i][k][j] = last[k];
      if (j > 0) last[str[i][j - 1] - 'a'] = j;
    }
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  for (int i = 0; i < m; ++i) sum[i + 1] = sum[i] + str[a[i]].length();
  for (int i = m - 1; i >= 0; --i)
    for (int j = 0; j < 26; ++j) {
      next2[i][j] = next1[a[i]][j][0];
      if (next2[i][j] == -1 && i < m - 1 && next2[i + 1][j] != -1) {
        next2[i][j] = str[a[i]].length() + next2[i + 1][j];
      }
    }
  scanf("%s", buf);
  int len = strlen(buf);
  for (int i = 0; i <= len; ++i)
    for (int j = 0; j <= len; ++j) f[i][j] = INT_MAX;
  f[0][0] = 0;
  for (int i = 1; i <= len; ++i)
    for (int j = 0; j <= i; ++j) {
      f[i][j] = f[i - 1][j];
      if (j > 0 && f[i - 1][j - 1] != INT_MAX) {
        int pos = f[i - 1][j - 1];
        int loc = lower_bound(sum, sum + m, pos + 1) - sum - 1;
        int tmp = -1;
        int ch = buf[i - 1] - 'a';
        if (loc < m && next1[a[loc]][ch][pos - sum[loc]] != -1) {
          tmp = next1[a[loc]][ch][pos - sum[loc]] + sum[loc];
        } else if (loc + 1 < m && next2[loc + 1][ch] != -1) {
          tmp = next2[loc + 1][ch] + sum[loc + 1];
        }
        if (tmp != -1) f[i][j] = min(f[i][j], tmp);
      }
    }
  for (int i = len; i >= 0; --i)
    if (f[len][i] != INT_MAX) {
      printf("%d\n", i);
      break;
    }
  return 0;
}
