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>
using namespace std;
int n, m, f[1005][1005], ans, a[1005], b[1005], c[25], cnt[10], vis[1005], clk;
char st[1005];
struct num {
  int v[1005], len;
  void read() {
    int i;
    scanf("%s", st + 1);
    len = strlen(st + 1);
    for (i = 1; i <= len; i++)
      if (st[len - i + 1] >= '0' && st[len - i + 1] <= '9')
        v[i] = st[len - i + 1] - '0';
      else
        v[i] = -1;
  }
} A, B[1005];
int main() {
  int i, j, k, l, S;
  A.read(), m = A.len;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) B[i].read(), m = max(m, B[i].len);
  for (i = 0; i <= 9; i++) scanf("%d", &c[i]);
  for (i = 1; i <= n; i++) a[i] = i;
  for (i = 0; i <= m; i++)
    for (j = 0; j <= n; j++) f[i][j] = -(1 << 30);
  f[0][0] = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j < 10; j++) cnt[j] = 0;
    for (j = 1; j <= n; j++) cnt[B[j].v[i + 1]]++;
    for (j = 9; j >= 0; j--) cnt[j] += cnt[j + 1];
    for (j = n; j >= 1; j--) b[cnt[B[a[j]].v[i + 1]]--] = a[j];
    for (j = (i + 1 == A.len); j <= 9; j++) {
      if (A.v[i + 1] != -1 && j != A.v[i + 1]) continue;
      ++clk, S = 0;
      for (k = 1; k <= n; k++)
        if (i + 1 <= A.len || i + 1 <= B[k].len)
          S += c[(B[k].v[i + 1] + j) % 10];
      for (k = 0, l = 0; k <= n; k++) {
        if (k) {
          vis[a[k]] = clk;
          S += c[(B[a[k]].v[i + 1] + j + 1) % 10];
          if (i + 1 <= B[a[k]].len || i + 1 <= A.len)
            S -= c[(B[a[k]].v[i + 1] + j) % 10];
        }
        while (l < n && B[b[l + 1]].v[i + 1] + j + (vis[b[l + 1]] == clk) >= 10)
          l++;
        f[i + 1][l] = max(f[i + 1][l], f[i][k] + S);
      }
    }
    for (j = n; j >= 1; j--) a[j] = b[j];
  }
  ans = -(1 << 30);
  for (i = 0; i <= n; i++) ans = max(ans, f[m][i] + i * c[1]);
  cout << ans;
  return 0;
}