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 = 1007;
const int G = 19491001;
const int mod = 1019260817;
const int mxlen = 1001;
void Min(int &x, int y) {
  if (x > y) x = y;
}
void Max(int &x, int y) {
  if (x < y) x = y;
}
string s[N], now;
int n, len[N], Len, w[N], has[N][N], dp[N][N], p[N], Pow[N], hz[N], hv[N];
int get(int x, int l, int r) {
  return (has[x][r] - (l == 0 ? 0 : has[x][l - 1]) + mod) % mod;
}
int D[N], arr[N], tot;
bool cmp(int x, int y) { return D[x] > D[y]; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> now >> n, Len = now.size(), reverse(now.begin(), now.end());
  Pow[0] = 1;
  for (int i = 1, iE = 1001; i <= iE; i++)
    Pow[i] = (long long)Pow[i - 1] * G % mod;
  for (int i = 1, iE = n; i <= iE; i++)
    cin >> s[i], len[i] = (int)s[i].size(), reverse(s[i].begin(), s[i].end()),
                 p[i] = i;
  for (int i = 0, iE = 9; i <= iE; i++) cin >> w[i];
  for (int i = 1, iE = n; i <= iE; i++) {
    for (int j = 0, jE = len[i] - 1; j <= jE; j++) {
      has[i][j] = (long long)s[i][j] * Pow[j] % mod;
      if (j) (has[i][j] += has[i][j - 1]) %= mod;
    }
  }
  for (int i = 1, iE = n; i <= iE; i++) D[i] = 1;
  memset(dp, -0x3f, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0, iE = mxlen; i <= iE; i++) {
    if (i) {
      tot = 0;
      for (int j = 1, jE = n; j <= jE; j++)
        if (i <= len[j]) D[j] += (s[j][i - 1] - '0') * (n + 1);
      for (int j = 1, jE = n; j <= jE; j++) arr[++tot] = D[j];
      sort(arr + 1, arr + tot + 1),
          tot = unique(arr + 1, arr + tot + 1) - arr - 1;
      for (int j = 1, jE = n; j <= jE; j++)
        D[j] = lower_bound(arr + 1, arr + tot + 1, D[j]) - arr;
      sort(p + 1, p + n + 1, cmp);
    }
    int l = (i == Len - 1), r = 9;
    if ((int)Len <= i)
      l = r = 0;
    else if (now[i] != '?')
      l = r = now[i] - '0';
    for (int d = l, dE = r; d <= dE; d++) {
      int now = 0, all = 0;
      for (int j = n, jE = 1; j >= jE; j--) {
        int v = (i > len[p[j]] - 1 ? 0 : s[p[j]][i] - '0');
        hv[j] = hv[j + 1], hz[j] = hz[j + 1];
        if (v + d || i < max(len[p[j]], Len))
          hv[j] += w[(v + d) % 10], hz[j] += (v + d) / 10;
      }
      for (int j = 0, jE = n; j <= jE; j++) {
        if (j) {
          int v = (i > len[p[j]] - 1 ? 0 : s[p[j]][i] - '0');
          all += w[(v + d + 1) % 10];
          now += (v + d + 1) / 10;
        }
        Max(dp[i + 1][now + hz[j + 1]], dp[i][j] + all + hv[j + 1]);
      }
    }
  }
  cout << dp[mxlen + 1][0] << endl;
  return 0;
}