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>
const int MAXN = 1010;
int C[10];
char buf[MAXN];
int arr[MAXN][MAXN], bse[MAXN];
int n, L;
int dp[MAXN][MAXN], rk[MAXN][MAXN];
int buc[10], cnt[10], suc[11];
int dig[MAXN];
void add(int x, int v) {
  cnt[x] += v;
  for (int i = 0; i < 10; ++i) buc[i] += v * C[(i + x) % 10];
}
void gma(int& x, int y) { x < y ? x = y : 0; }
int main() {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cin >> buf;
  int BL = strlen(buf);
  L = BL;
  for (int i = 0; i < L; ++i) bse[L - i] = buf[i] == '?' ? -1 : buf[i] - '0';
  std::cin >> n;
  for (int T = 1; T <= n; ++T) {
    std::cin >> buf;
    int t = strlen(buf);
    dig[T] = std::max(t, BL);
    for (int i = 0; i < t; ++i) arr[T][t - i] = buf[i] - '0';
    L = std::max(L, t);
  }
  ++L;
  for (int i = 0; i < 10; ++i) std::cin >> C[i];
  memset(dp, 0xcf, sizeof dp);
  const int NINF = **dp;
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) rk[0][i] = i;
  for (int i = 1; i <= L; ++i) {
    memset(buc, 0, sizeof buc);
    for (int j = 1; j <= n; ++j) ++buc[arr[j][i]];
    for (int j = 1; j < 10; ++j) buc[j] += buc[j - 1];
    for (int j = n; j; --j) {
      int u = rk[i - 1][j];
      rk[i][buc[arr[u][i]]--] = u;
    }
    int DOWN = i == BL, UP = 9;
    if (bse[i] != -1) DOWN = UP = bse[i];
    memset(buc, 0, sizeof buc);
    memset(cnt, 0, sizeof cnt);
    int up = 0, dta = 0;
    for (int j = 1; j <= n; ++j) {
      add(arr[j][i], 1);
      if (i > dig[j]) dta += C[0];
    }
    for (int j = 0; j <= n; ++j) {
      if (j) {
        int u = rk[i - 1][n - j + 1];
        add(arr[u][i], -1);
        add((arr[u][i] + 1) % 10, 1);
        up += arr[u][i] == 9;
        if (i > dig[u]) dta -= C[0];
      }
      if (dp[i - 1][j] == NINF) continue;
      for (int k = 0; k < 10; ++k) suc[k] = cnt[k];
      for (int k = 9; ~k; --k) suc[k] += suc[k + 1];
      for (int k = DOWN; k <= UP; ++k)
        gma(dp[i][suc[10 - k] + up], buc[k] + dp[i - 1][j] - dta);
    }
  }
  int ans = *std::max_element(dp[L], dp[L + 1]);
  std::cout << ans << std::endl;
  return 0;
}