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;
char s[1300];
char t[1300][1300];
int f[1300][1300];
int len[1300], maxx, n;
vector<int> v[1300][1300];
int a[13], pp[1300];
int nn[1300], ll;
int cc(char x, int d, int b, int c) {
  if (x == '-' && d == 0 && b >= c)
    return 0;
  else if (x == '-')
    return a[d % 10];
  else
    return a[(x - '0' + d) % 10];
}
struct node {
  int x, y, z;
} pl[1100];
int cmp(node a, node b) {
  if (a.y != b.y)
    return a.y > b.y;
  else
    return a.x < b.x;
}
int main() {
  memset(f, -1, sizeof(f));
  scanf("%s", s);
  maxx = ll = strlen(s);
  reverse(s, s + maxx);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%s", t[i]), len[i] = strlen(t[i]), maxx = max(maxx, len[i]),
                       reverse(t[i], t[i] + len[i]);
  maxx += 200;
  for (int i = strlen(s); i < maxx; i++) s[i] = '0';
  for (int i = 1; i <= n; i++)
    for (int j = len[i]; j < maxx; j++) t[i][j] = '-';
  for (int i = 0; i < 10; i++) scanf("%d", &a[i]);
  f[0][0] = 0;
  for (int i = 1; i <= n; i++) v[0][1].push_back(i);
  for (int i = 0; i < maxx; i++) {
    for (int j = 0; j <= 9; j++) {
      if (s[i] != '?' && s[i] != j + '0') continue;
      if (i == ll - 1 && j == 0) continue;
      memset(pp, 0, sizeof(pp));
      int ans = 0, nu = 0;
      for (int k = 1; k <= n; k++) {
        ans += cc(t[k][i], j, i, ll);
        if ((t[k][i] == '-' ? '0' : t[k][i]) - '0' + j > 9) pp[k] = 1, nu++;
      }
      for (int k = 0; k <= n; k++) {
        for (int l = 0; l < v[i][k].size(); l++) {
          ans -= cc(t[v[i][k][l]][i], j, i, ll);
          ans += cc(t[v[i][k][l]][i], j + 1, i, ll);
          if ((t[v[i][k][l]][i] == '-' ? '0' : t[v[i][k][l]][i]) - '0' + j + 1 >
                  9 &&
              !pp[v[i][k][l]])
            pp[v[i][k][l]] = 1, nu++;
        }
        if (f[i][k] == -1) continue;
        f[i + 1][nu] = max(f[i + 1][nu], f[i][k] + ans);
      }
    }
    for (int j = 1; j <= n; j++)
      pl[j].x = nn[j], pl[j].y = (t[j][i] == '-' ? '0' : t[j][i]) - '0',
      pl[j].z = j;
    sort(pl + 1, pl + 1 + n, cmp);
    pl[n + 1].x = -1;
    for (int j = n; j >= 1; j--)
      if (pl[j].x == pl[j + 1].x && pl[j].y == pl[j + 1].y)
        nn[pl[j].z] = nn[pl[j + 1].z];
      else
        nn[pl[j].z] = j;
    for (int j = 1; j <= n; j++) v[i + 1][nn[j]].push_back(j);
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, f[maxx][i]);
  cout << ans << endl;
  return 0;
}