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;
const int N = 1024;
char a0[N], a[N], b0[N][N], b[N][N];
int c[16], n, len, la, p0;
bool ban[N][N];
void init(char *s0, char *s, bool *ban) {
  int x = strlen(s0 + 1), p = len - x + 1;
  for (int i = 1; i <= p - 1; ++i) s[i] = 0, ban == NULL ? 0 : ban[i] = i < p0;
  for (int i = 1; i <= x; ++i) s[p++] = s0[i] == '?' ? -1 : s0[i] & 15;
}
int rk[N][N], kth[N][N], dp[N][N];
int main() {
  scanf("%s%d", a0 + 1, &n);
  len = la = strlen(a0 + 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", b0[i] + 1);
    len = max(len, (int)strlen(b0[i] + 1));
  }
  ++len;
  p0 = len - la + 1;
  for (int i = 0; i <= 9; ++i) scanf("%d", c + i);
  init(a0, a, NULL);
  for (int i = 1; i <= n; ++i) init(b0[i], b[i], ban[i]);
  for (int i = 1; i <= n; ++i) rk[len + 1][i] = kth[len + 1][i] = i;
  for (int t = len + 1; t >= 0; --t)
    for (int i = 0; i <= n + 1; ++i) dp[t][i] = -1;
  dp[len + 1][n + 1] = 0;
  for (int t = len; t >= 1; --t) {
    static int ord[N];
    for (int i = 1; i <= n; ++i) ord[i] = i;
    sort(ord + 1, ord + n + 1, [&](int x, int y) {
      return b[x][t] == b[y][t] ? rk[t + 1][x] < rk[t + 1][y]
                                : b[x][t] < b[y][t];
    });
    for (int i = 1; i <= n; ++i) rk[t][ord[i]] = i, kth[t][i] = ord[i];
    for (int num = 9; num >= 0; --num) {
      if (t == p0 && !num) continue;
      if (~a[t] && a[t] != num) continue;
      int id = n + 1;
      for (int i = 1; i <= n; ++i)
        if (b[i][t] >= 10 - num) id = min(id, rk[t][i]);
      int w = 0;
      for (int i = 1; i <= n; ++i)
        w += !num && ban[i][t] ? 0 : c[(b[i][t] + num) % 10];
      for (int i = n + 1; i >= 1; --i) {
        if (i <= n) {
          int u = kth[t + 1][i];
          if (b[u][t] >= 9 - num) id = min(id, rk[t][u]);
          w += c[(b[u][t] + num + 1) % 10] -
               (!num && ban[u][t] ? 0 : c[(b[u][t] + num) % 10]);
        }
        if (~dp[t + 1][i]) dp[t][id] = max(dp[t][id], dp[t + 1][i] + w);
      }
    }
  }
  printf("%d\n", dp[1][n + 1]);
  return 0;
}