Paul Erdős's prediction came true. Finally an alien force landed on the Earth. In contrary to our expectation they didn't asked the humans to compute the value of a Ramsey number (maybe they had solved it themselves). They asked another question which seemed as hard as calculating Ramsey numbers. Aliens threatened that if humans don't solve this problem in less than 2 hours they will destroy the Earth. 

Before telling the problem they introduced the concept of Hyper Strings. A Hyper String is made by concatenation of some base strings. Suppose you are given a list of base strings b1, b2, ..., bn. Now the Hyper String made from indices list i1, i2, ..., im is concatenation of base strings bi1, bi2, ..., bim. A Hyper String can be very large and doing operations on it is very costly for computers. 

The aliens asked humans to compute the length of the longest common sub-sequence of a Hyper String t with a string s.

Input

The first line of input contains the single integer n (1 ≤ n ≤ 2000) — the number of base strings. 

The next n lines contains values of base strings. Each base string is made of lowercase Latin letters. A base string cannot be empty string and the sum of lengths of all n base strings doesn't exceed 106. 

The next line contains the single integer m (1 ≤ m ≤ 2000) — the number of base strings in the given Hyper String t. 

The next line contains m space-separated integer numbers i1, i2, ..., im (1 ≤ ij ≤ n) — the indices of base strings in the Hyper String t.

The last line contains a non-empty string s. String s is made of lowercase Latin letters and its length is no more than 2000 characters.

Output

Print the length of longest common sub-sequence of Hyper String t and string s. If there is no common sub-sequence print 0.

Examples

Input

2
cba
dgh
2
1 2
aedfhr


Output

3


Input

2
b
a
5
1 2 1 2 1
aaa


Output

2

Note

The length of string s is the number of characters in it. If the length of string s is marked as |s|, then string s can be represented as s = s1s2... s|s|.

A non-empty string y = s[p1p2... p|y|] = sp1sp2... sp|y| (1 ≤ p1 < p2 < ... < p|y| ≤ |s|) is a subsequence of string s. For example, "coders" is a subsequence of "codeforces".
#include <bits/stdc++.h>
using namespace std;
int n, m;
string b[2048], s;
int idx[2048];
pair<int, int> dp[2048][2048];
vector<int> ps[2048][32];
int suf[2048][32];
int get_pos(int ix, int lo, char ch) {
  const int c = ch - 'a';
  return *lower_bound(ps[ix][c].begin(), ps[ix][c].end(), lo);
}
int get_ix(int lo, char ch) {
  const int c = ch - 'a';
  return suf[lo][c];
}
int main() {
  cin >> n;
  for (int i = 0; i < (int)(n); i++) cin >> b[i];
  cin >> m;
  for (int i = 0; i < (int)(m); i++) cin >> idx[i];
  for (int i = 0; i < (int)(m); i++) idx[i]--;
  cin >> s;
  for (int k = 0; k < (int)(n); k++) {
    for (int i = 0; i < (int)(b[k].size()); i++) {
      const int c = b[k][i] - 'a';
      ps[k][c].push_back(i);
    }
    for (int i = 0; i < (int)(32); i++) ps[k][i].push_back((1 << 28));
  }
  for (int i = 0; i < (int)(32); i++) suf[m][i] = (1 << 28);
  for (int k = m - 1; k >= 0; k--) {
    for (int i = 0; i < (int)(32); i++) suf[k][i] = suf[k + 1][i];
    for (int i = 0; i < (int)(32); i++)
      if (ps[idx[k]][i].size() > 1) suf[k][i] = k;
  }
  for (int i = 0; i < (int)(2048); i++)
    for (int j = 0; j < (int)(2048); j++) dp[i][j].first = (1 << 28);
  dp[0][0] = make_pair(0, -1);
  for (int i = 0; i < (int)(2048); i++) {
    for (int j = 0; j < (int)(s.size()); j++)
      if (dp[i][j].first < (1 << 28)) {
        const int cix = dp[i][j].first;
        const int cpos = dp[i][j].second;
        const int sp = get_pos(idx[cix], cpos + 1, s[j]);
        if (sp < (1 << 28)) {
          dp[i + 1][j + 1] = min(dp[i + 1][j + 1], make_pair(cix, sp));
        } else {
          const int nix = get_ix(cix + 1, s[j]);
          if (nix < (1 << 28)) {
            const int npos = get_pos(idx[nix], 0, s[j]);
            dp[i + 1][j + 1] = min(dp[i + 1][j + 1], make_pair(nix, npos));
          }
        }
        dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
      }
  }
  int ans = 0;
  for (int i = 0; i < (int)(2048); i++)
    for (int j = 0; j < (int)(2048); j++)
      if (dp[i][j].first < (1 << 28)) ans = i;
  cout << ans << endl;
  return 0;
}
