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 = 1e3 + 5;
struct num {
  int x[N], sz;
  friend istream &operator>>(istream &get, num &n) {
    string s;
    get >> s, n.sz = s.size();
    for (int i = 0; i < n.sz; i++)
      n.x[n.sz - i - 1] = (s[i] ^ '?' ? s[i] - '0' : -1);
    return get;
  }
} a, b[N];
int n, m, c[10], id[N], dp[N][N];
int main() {
  cin >> a >> n, m = a.sz + 1;
  for (int i = 0; i < n; i++) {
    cin >> b[id[i] = i];
    m = max(m, b[i].sz + 1);
  }
  for (int i = 0; i < 10; i++) cin >> c[i];
  memset(dp, -63, sizeof dp);
  for (int p = dp[0][0] = 0; p < m; p++) {
    for (int r = 9, l = (~a.x[p] ? r = a.x[p] : p + 1 >= a.sz), k = l; k <= r;
         k++) {
      int ten = 0, cost = 0;
      for (int i = 0; i < n; i++) {
        int w = b[i].x[p] + k;
        cost += max(a.sz, b[i].sz) > p || w ? c[w % 10] : 0, ten += w > 9;
      }
      for (int i = 0; i <= n; i++) {
        int w = b[id[i]].x[p] + k;
        dp[p + 1][ten] = max(dp[p + 1][ten], dp[p][i] + cost);
        cost +=
            c[(w + 1) % 10] - (max(a.sz, b[id[i]].sz) > p || w ? c[w % 10] : 0),
            ten += w < 9 ? 0 : w == 9;
      }
    }
    stable_sort(id, id + n,
                [p](int i, int j) { return b[i].x[p] > b[j].x[p]; });
  }
  cout << dp[m][0];
}