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 = 1e6;
const int M = 123;
const long double Pi = acos(-1);
const long long Inf = 1e18;
const int inf = 1e9;
const int mod = 1000200013;
const long double eps = 1e-9;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) { return 1ll * a * b % mod; }
int sum(int a, int b) {
  add(a, b);
  return a;
}
string A, b[N];
int n, Sz, id[2][N], dp[2][N], cnt[11], c[11];
int Let(int pos, int i) {
  int ans = (pos <= b[i].size() ? b[i][pos - 1] : '0') - '0';
  return ans;
}
void Sort(int pos) {
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; i++) {
    cnt[Let(pos, i)]++;
  }
  for (int i = 0; i < 9; i++) {
    cnt[i + 1] += cnt[i];
  }
  for (int i = 1; i <= n; i++) {
    id[0][cnt[Let(pos, id[1][i])]--] = id[1][i];
  }
  reverse(id[0] + 1, id[0] + n + 1);
}
void Upd(int &a, int b) { a = max(a, b); }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> A;
  reverse(A.begin(), A.end());
  Sz = max(Sz, (int)A.size());
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    reverse(b[i].begin(), b[i].end());
    Sz = max(Sz, (int)b[i].size());
  }
  for (int i = 0; i < 10; i++) {
    cin >> c[i];
  }
  Sz++;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 2; j++) {
      dp[j][i] = -inf;
    }
    id[0][i] = i;
  }
  dp[0][0] = 0;
  for (int pos = 1; pos <= Sz; pos++) {
    for (int i = 0; i <= n; i++) {
      dp[1][i] = dp[0][i];
      id[1][i] = id[0][i];
      dp[0][i] = -inf;
    }
    memset(cnt, 0, sizeof cnt);
    for (int i = 1; i <= n; i++) {
      if (max((int)A.size(), (int)b[id[1][i]].size()) >= pos) {
        cnt[Let(pos, id[1][i])]++;
      }
    }
    for (int i = 0; i <= n; i++) {
      if (i > 0) {
        if (max((int)A.size(), (int)b[id[1][i]].size()) < pos) {
          cnt[1]++;
        } else {
          int now = Let(pos, id[1][i]);
          cnt[now + 1]++;
          cnt[now]--;
        }
      }
      if (dp[1][i] < 0) continue;
      int l = 0, r = 9;
      if (pos <= A.size()) {
        if (A[pos - 1] != '?') {
          l = r = A[pos - 1] - '0';
        } else {
          if (pos == A.size()) {
            l++;
          }
        }
      } else {
        r = 0;
      }
      for (int dig = l; dig <= r; dig++) {
        int cost = 0;
        int C = 0;
        for (int j = 0; j <= 10; j++) {
          if (dig + j > 9) {
            C += cnt[j];
          }
          cost += 1ll * cnt[j] * c[(j + dig) % 10];
        }
        Upd(dp[0][C], dp[1][i] + cost);
      }
    }
    Sort(pos);
  }
  cout << dp[0][0] << endl;
  return 0;
}