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;
const int N = 2005, C = 26, inf = 1000 * 1000 + 7;
vector<int> nxt[N][C];
int nxt2[N][C];
int a[N];
pair<int, int> dp[N][N];
string t[N];
string s;
int main() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    for (int j = 0; j < C; j++) {
      for (int k = 0; k <= t[i].size(); k++) {
        nxt[i][j].push_back(inf);
      }
    }
    for (int k = t[i].size() - 1; k >= 0; k--) {
      for (int j = 0; j < C; j++) {
        nxt[i][j][k] = nxt[i][j][k + 1];
      }
      nxt[i][t[i][k] - 'a'][k] = k;
    }
  }
  for (int j = 0; j < C; j++) {
    nxt[0][j].push_back(inf);
    nxt[0][j].push_back(inf);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < C; j++) {
    nxt2[m][j] = inf;
  }
  for (int i = m - 1; i >= 0; i--) {
    for (int j = 0; j < C; j++) {
      nxt2[i][j] = nxt2[i + 1][j];
      if (nxt[a[i + 1]][j][0] != inf) {
        nxt2[i][j] = i + 1;
      }
    }
  }
  cin >> s;
  for (int j = 1; j <= s.size(); j++) {
    dp[0][j] = {inf, 0};
  }
  dp[0][0] = {0, 0};
  for (int i = 1; i <= s.size(); i++) {
    for (int j = 0; j <= s.size(); j++) {
      dp[i][j] = dp[i - 1][j];
      if (j > 0) {
        pair<int, int> p = dp[i - 1][j - 1];
        if (p.first != inf) {
          if (nxt[a[p.first]][s[i - 1] - 'a'][p.second + 1] != inf) {
            dp[i][j] =
                min(dp[i][j],
                    {p.first, nxt[a[p.first]][s[i - 1] - 'a'][p.second + 1]});
          } else {
            int x = nxt2[p.first][s[i - 1] - 'a'];
            if (x != inf) {
              dp[i][j] = min(dp[i][j], {x, nxt[a[x]][s[i - 1] - 'a'][0]});
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int j = 1; j <= s.size(); j++) {
    if (dp[s.size()][j].first < inf) {
      ans = j;
    }
  }
  cout << ans;
  return 0;
}
