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;
char p[1010];
int w[1010], L, n, P[1010][1010], m, Rank[1010], Len[1010];
int D[1010][1010], SS[10], CC[10];
struct A {
  int a, num;
  bool operator<(const A &p) const { return a < p.a; }
} ord[1010];
int score[10];
void Ins(int a, int pv, int b, int ck) {
  int i;
  for (i = 0; i < 10; i++) {
    if (i == 0) {
      if (!b && Len[a] < pv && L < pv) continue;
    }
    SS[i] += score[(b + i) % 10] * ck;
    if (i + b >= 10) CC[i] += ck;
  }
}
int main() {
  int i, j, k;
  scanf("%s", p);
  for (i = 0; p[i]; i++)
    ;
  L = i;
  for (i = 0; i < L; i++) {
    if (p[L - i - 1] == '?')
      w[i + 1] = -1;
    else
      w[i + 1] = p[L - i - 1] - '0';
  }
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", p);
    for (j = 0; p[j]; j++)
      ;
    int tt = j;
    for (j = 0; j < tt; j++) {
      P[i][j + 1] = p[tt - j - 1] - '0';
    }
    Len[i] = tt;
  }
  for (i = 0; i < 10; i++) scanf("%d", &score[i]);
  m = 1006;
  for (i = 0; i <= m; i++)
    for (j = 0; j <= m; j++) D[i][j] = -1;
  D[0][0] = 0;
  for (i = 0; i < m; i++) {
    for (j = 1; j <= n; j++)
      ord[j].a = Rank[j] + P[j][i] * 10000, ord[j].num = j;
    sort(ord + 1, ord + n + 1);
    for (j = 1; j <= n; j++) Rank[ord[j].num] = j;
    for (j = 0; j < 10; j++) CC[j] = SS[j] = 0;
    for (j = 1; j <= n; j++) Ins(j, i + 1, P[j][i + 1], 1);
    for (j = 0; j <= n; j++) {
      if (D[i][j] != -1) {
        for (k = 0; k < 10; k++) {
          if (i + 1 == L && k == 0) continue;
          if (w[i + 1] != -1 && w[i + 1] != k) continue;
          D[i + 1][CC[k]] = max(D[i + 1][CC[k]], D[i][j] + SS[k]);
        }
      }
      if (j == n) break;
      int tp = ord[n - j].num;
      Ins(tp, i + 1, P[tp][i + 1], -1);
      Ins(tp, i + 1, P[tp][i + 1] + 1, 1);
    }
  }
  printf("%d\n", D[m][0]);
}