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 maxn = 1e3 + 10;
char s[maxn], tmp[maxn];
int x[maxn][maxn], f[maxn][maxn];
int len[maxn];
int rk[maxn][maxn], sa[maxn][maxn];
int v[maxn];
int c[11];
int n, m, l;
void sort() {
  for (int i = 1; i <= n; ++i) sa[0][i] = i;
  for (int i = 1; i <= m; ++i) {
    memset(v, 0, sizeof(v));
    for (int j = 1; j <= n; ++j) v[x[j][i]]++;
    for (int j = 8; j >= 0; --j) v[j] += v[j + 1];
    for (int j = n; j >= 1; --j) rk[i][sa[i - 1][j]] = v[x[sa[i - 1][j]][i]]--;
    for (int j = 1; j <= n; ++j) sa[i][rk[i][j]] = j;
  }
}
int upd, num;
int work(int k, int d) {
  int _n = n, ret = 0;
  for (int i = 1; i <= n; ++i) {
    int j = sa[k][i], y = x[j][k] + d;
    if (_n == n && y < 10) _n = i - 1;
    if (l < k && len[j] < k && !y) continue;
    ret += c[y % 10], upd += y >= 10;
  }
  if (f[k - 1][0] >= 0) f[k][upd] = max(f[k][upd], f[k - 1][0] + ret);
  return ret;
}
void solve(int i, int j, int d) {
  int y = x[j][i] + d;
  num += c[(y + 1) % 10] - c[y % 10];
  if (l < i && len[j] < i && !y) num += c[y % 10];
  upd += (y == 9);
}
int t;
int main() {
  m = 1000;
  scanf("%s", tmp);
  l = strlen(tmp);
  for (int i = 1; i <= l; ++i) s[i] = tmp[l - i];
  for (int i = l + 1; i <= m; ++i) s[i] = '0';
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", tmp);
    len[i] = strlen(tmp);
    for (int j = 1; j <= len[i]; ++j) x[i][j] = tmp[len[i] - j] - '0';
  }
  sort();
  for (int i = 0; i <= 9; ++i) scanf("%d", &c[i]);
  memset(f, -1, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= m; ++i) {
    if (s[i] == '?') {
      for (int d = 0; d <= 9; ++d) {
        if (i == l && !d) continue;
        upd = 0, num = work(i, d), ++t;
        for (int j = 1; j <= n; ++j) {
          solve(i, sa[i - 1][j], d);
          if (f[i - 1][j] >= 0) f[i][upd] = max(f[i][upd], f[i - 1][j] + num);
        }
      }
    } else {
      int d = s[i] - '0';
      upd = 0, num = work(i, d);
      for (int j = 1; j <= n; ++j) {
        solve(i, sa[i - 1][j], d);
        if (f[i - 1][j] >= 0) f[i][upd] = max(f[i][upd], f[i - 1][j] + num);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) ans = max(ans, f[m][i] + i * c[1]);
  printf("%d\n", ans);
}