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;
int n, dim, i, j, global, d1;
char s[1024];
int patt[1024], dd[1024];
int nr[1024][1024];
int cost[11];
long long dp[1024][1024];
vector<int> radix[11], ord;
int cnt[11];
void rev(char* a, char* b) {
  while (a < b) {
    swap(*a, *b);
    a++;
    b--;
  }
}
int main() {
  scanf("%s\n", s + 1);
  dim = strlen(s + 1);
  rev(s + 1, s + dim);
  for (i = 1; i <= dim; i++) {
    if (s[i] == '?')
      patt[i] = -1;
    else
      patt[i] = s[i] - '0';
  }
  d1 = dim;
  global = dim;
  scanf("%d\n", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s\n", s + 1);
    dim = dd[i] = strlen(s + 1);
    global = max(global, dim);
    rev(s + 1, s + dim);
    for (j = 1; j <= dim; j++) nr[i][j] = s[j] - '0';
    dd[i] = max(dd[i], d1);
  }
  for (i = 0; i < 10; i++) scanf("%d", &cost[i]);
  for (i = 0; i <= dim; i++)
    for (j = 0; j <= n; j++) dp[i][j] = -1LL << 60;
  dim = global;
  for (i = 1; i <= n; i++) ord.push_back(i);
  dp[1][0] = 0;
  for (i = 1; i <= dim; i++) {
    memset(cnt, 0, sizeof(cnt));
    for (j = 1; j <= n; j++)
      if (nr[j][i] != 0 || dd[j] >= i) cnt[nr[j][i]]++;
    for (j = 0; j <= n; j++) {
      if (j > 0) {
        if (nr[ord[j - 1]][i] != 0 || dd[ord[j - 1]] >= i)
          cnt[nr[ord[j - 1]][i]]--;
        cnt[nr[ord[j - 1]][i] + 1]++;
      }
      if (dp[i][j] < 0) continue;
      for (int cf = 0; cf < 10; cf++) {
        if (patt[i] != -1 && patt[i] != cf) continue;
        if (i == d1 && cf == 0) continue;
        int pl = 0;
        long long new_sum = dp[i][j];
        for (int act = 0; act < 11; act++) {
          int go = act + cf;
          pl += (go / 10) * cnt[act];
          go %= 10;
          new_sum += 1LL * cost[go] * cnt[act];
        }
        dp[i + 1][pl] = max(dp[i + 1][pl], new_sum);
      }
    }
    for (j = 0; j < 10; j++) radix[j].clear();
    for (auto e : ord) radix[nr[e][i]].push_back(e);
    ord.clear();
    for (j = 9; j >= 0; j--)
      for (auto e : radix[j]) ord.push_back(e);
  }
  long long ans = 0;
  for (i = 0; i <= n; i++) ans = max(ans, dp[dim + 1][i] + 1LL * cost[1] * i);
  printf("%lld", ans);
  return 0;
}