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;
void getre() {
  int x = 0;
  printf("%d\n", 1 / x);
}
void gettle() {
  int res = 1;
  while (1) res <<= 1;
  printf("%d\n", res);
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
template <typename N>
inline int sgn(N a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gs(char *s) { scanf("%s", s); }
inline void gc(char &c) {
  while ((c = getchar()) > 126 || c < 33)
    ;
}
inline void pc(char c) { putchar(c); }
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846264338327950288L;
const double eps = 1e-6;
char stradd[1111];
int canaddl[1111], canaddr[1111];
int lenl[1111], lenr[1111];
int n;
int a[1111][1111];
char str[1111];
int cost[10];
int l = 1005;
int f[1111][1111];
int sa[1111];
int pos[1111];
inline int co(int i, int ch, int pos) {
  if (ch != 0) return cost[ch];
  if (pos >= lenr[i]) return 0;
  return cost[0];
}
int curpos;
int cmp(int i, int j) {
  if (a[i][curpos] != a[j][curpos])
    return a[i][curpos] > a[j][curpos];
  else
    return pos[i] < pos[j];
}
int main() {
  gs(stradd);
  int len = strlen(stradd);
  for (int i = (0), _ed = (len); i < _ed; i++) {
    int pos = len - i;
    if (i == 0 && stradd[i] == '?') {
      canaddl[pos] = 1;
      canaddr[pos] = 9;
    } else if (stradd[i] == '?') {
      canaddl[pos] = 0;
      canaddr[pos] = 9;
    } else {
      canaddl[pos] = stradd[i] - '0';
      canaddr[pos] = stradd[i] - '0';
    }
  }
  gn(n);
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    gs(str);
    int le = strlen(str);
    for (int j = (0), _ed = (le); j < _ed; j++) a[i][le - j] = str[j] - '0';
    lenl[i] = max(le, len);
    lenr[i] = max(le, len) + 1;
  }
  for (int i = (0), _ed = (10); i < _ed; i++) gn(cost[i]);
  memset((f), (-64), sizeof(f));
  f[0][0] = 0;
  for (int i = (1), _ed = (n + 1); i < _ed; i++) sa[i] = i;
  for (int i = (1), _ed = (l + 1); i < _ed; i++) {
    for (int ad = (canaddl[i]), _ed = (canaddr[i] + 1); ad < _ed; ad++) {
      int jin = 0;
      int su = 0;
      for (int j = (1), _ed = (n + 1); j < _ed; j++) {
        int x = a[j][i];
        su += co(j, (ad + x) % 10, i);
        if (ad + x >= 10) jin++;
      }
      int cur = 1;
      for (int t = (0), _ed = (n + 1); t < _ed; t++) {
        if (t) {
          int j = sa[t];
          int x = a[j][i];
          su -= co(j, (ad + x) % 10, i);
          su += co(j, (ad + x + 1) % 10, i);
          if (ad + x + 1 == 10) jin++;
        }
        if (su + f[i - 1][t] >= 0) upmax(f[i][jin], su + f[i - 1][t]);
      }
    }
    for (int t = (1), _ed = (n + 1); t < _ed; t++) pos[sa[t]] = t;
    curpos = i;
    sort(sa + 1, sa + 1 + n, cmp);
  }
  printf("%d\n", f[l][0]);
  return 0;
}