Problem: Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the maximum cost possible.

Recently Boris got hold of the magical artifact A, which can allow him to increase the cost of his collection. Artifact is a string, consisting of digits and '?' symbols. To use the artifact, Boris must replace all '?' with digits to get a decimal number without leading zeros (it is also not allowed to get number 0). After that, the resulting number is added to all numbers Bi in Boris' collection. He uses the artifact exactly once.

What is the maximum cost of the collection Boris can achieve after using the artifact?

Input

First line contains artifact A, consisting of digits '0'–'9' and '?' symbols (1 ≤ |A| ≤ 1000). Next line contains n — the amount of numbers in Boris' collection (1 ≤ n ≤ 1000). Next n lines contain integers Bi (1 ≤ Bi < 101000). A doesn't start with '0'.

Last line contains ten integers — costs of digits c0, c1, ..., c9 (0 ≤ ci ≤ 1000).

Output

Output one integer — the maximum possible cost of the collection after using the artifact.

Examples

Input

42
3
89
1
958
0 0 1 1 2 2 3 3 4 4


Output

4


Input

?5?
4
2203
5229
276
6243
2 1 6 1 1 2 5 2 2 3


Output

62

Note

In the second sample input, the optimal way is to compose the number 453. After adding this number, Boris will have numbers 2656, 5682, 729 and 6696. The total cost of all digits in them is equal to 18 + 15 + 11 + 18 = 62. 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
char s[1000][1010], t[1010];
int dp[1010][1001], a[1000], p[1000], f[1000], c[20], n;
bool b[1001];
int len[1000], l;
inline int cost(int i, int j, int x) {
  return x || j < len[i] || j < l ? c[x] : 0;
}
inline void umax(int& m, int u) { u > m && (m = u); }
void sort(int d) {
  static int b[10][1000], c[1000], l[10];
  int i, j, k = 0;
  for (i = 0; i < 10; i++) l[i] = 0;
  for (i = 0; i < n; i++) j = s[a[i]][d] - '0', b[j][l[j]++] = i;
  for (i = 9; i >= 0; i--)
    for (j = 0; j < l[i]; j++) c[k++] = b[i][j];
  for (i = 0; i < n; i++) p[i] = a[i];
  for (i = 0; i < n; i++) a[i] = p[c[i]];
  for (i = 0; i < n; i++) f[a[i]] = i;
}
int main() {
  int i, j, k, m, x, sum, cnt;
  scanf("%s%d", t, &n);
  l = (m = strlen(t)) - 1;
  std::reverse(t, t + m);
  while (m <= 1001) t[m++] = '0';
  for (i = 0; i < n; i++) {
    scanf("%s", s[i]);
    len[i] = j = strlen(s[i]);
    std::reverse(s[i], s[i] + j);
    while (j <= 1001) s[i][j++] = '0';
    a[i] = i;
  }
  for (i = 0; i < 10; i++) scanf("%d", c + i);
  for (i = 0; i < 10; i++) c[i + 10] = c[i];
  for (i = 0; i < m; i++) {
    sort(i);
    for (j = 0; j <= n; j++) dp[i][j] = -1.1e9;
    for (x = i == l ? 1 : 0; x < 10; x++) {
      if (t[i] != '?' && t[i] != x + '0') continue;
      sum = cnt = k = 0;
      for (j = 0; j < n; j++) {
        sum += cost(a[j], i, s[a[j]][i] - '0' + x);
        if (s[a[j]][i] - '0' + x > 9)
          k = j + 1, b[f[a[j]]] = true, cnt++;
        else
          b[f[a[j]]] = false;
      }
      if (!i)
        umax(dp[i][k], sum);
      else {
        if (k == cnt)
          umax(dp[i][k], sum + dp[i - 1][0]);
        else
          return 1;
        for (j = 0; j < n; j++) {
          if (s[p[j]][i] - '0' + x == 9) {
            b[f[p[j]]] = true;
            cnt++;
          }
          sum -= cost(p[j], i, s[p[j]][i] - '0' + x);
          sum += cost(p[j], i, s[p[j]][i] - '0' + x + 1);
          while (b[k]) k++;
          if (k == cnt)
            umax(dp[i][k], sum + dp[i - 1][j + 1]);
          else
            return 1;
        }
      }
    }
  }
  printf("%d\n", dp[m - 1][0]);
}