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;
inline int read() {
  int sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) return -sum;
  return sum;
}
const int N = 1005;
const int orz = 2000000000;
char s[N];
struct ex {
  int a[N], len;
  int &operator[](int x) { return a[x]; }
  inline void init() {
    scanf("%s", s + 1);
    len = strlen(s + 1);
    reverse(s + 1, s + len + 1);
    for (int i = 1; i <= len; i++)
      if (s[i] == '?')
        a[i] = -1;
      else
        a[i] = s[i] - '0';
  }
} BS, A[N];
int n, m, X, f[N][N], c[N], id1[N], id2[N], pos[N], vis[N], cnt;
inline void up(int &x, int y) {
  if (y > x) x = y;
}
inline bool cmp(const int &a, const int &b) {
  if (A[a][X] != A[b][X]) return A[a][X] > A[b][X];
  return pos[a] < pos[b];
}
int main() {
  int i, j, k, t, x, S, st;
  BS.init();
  n = read();
  m = BS.len;
  for (i = 1; i <= n; i++) A[i].init(), m = max(m, A[i].len);
  for (i = 0; i <= 9; i++) c[i] = read();
  for (i = 0; i <= m; i++)
    for (j = 0; j <= n; j++) f[i][j] = -orz;
  f[0][0] = 0;
  for (i = 1; i <= n; i++) id2[i] = i;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) id1[j] = j, pos[id2[j]] = j;
    X = i;
    sort(id1 + 1, id1 + n + 1, cmp);
    if (i == BS.len)
      st = 1;
    else
      st = 0;
    for (k = st; k <= 9; k++) {
      if (BS[i] != -1 && BS[i] != k) continue;
      for (S = 0, j = 1; j <= n; j++)
        if (i <= BS.len || i <= A[j].len) S += c[(A[j][i] + k) % 10];
      cnt++;
      for (t = 1, j = 0; j <= n; j++)
        if (f[i - 1][j] != orz) {
          if (j) {
            x = id2[j];
            if (i <= BS.len || i <= A[x].len) S -= c[(A[x][i] + k) % 10];
            S += c[(A[x][i] + k + 1) % 10], vis[x] = cnt;
          }
          while (t <= n) {
            x = id1[t];
            if (A[x][i] + k + (vis[x] == cnt) >= 10)
              t++;
            else
              break;
          }
          up(f[i][t - 1], f[i - 1][j] + S);
        }
    }
    for (j = 1; j <= n; j++) id2[j] = id1[j];
  }
  int ans = -orz;
  for (i = 0; i <= n; i++) up(ans, f[m][i] + c[1] * i);
  printf("%d", ans);
  return 0;
}