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;
template <class T>
inline void in(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) f |= (c == '-'), c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ '0'), c = getchar();
  f ? x = -x : 0;
}
template <class T>
inline void out(T x, const char c = '\n') {
  static short st[30];
  short tp = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++tp] = x % 10, x /= 10;
  while (x);
  while (tp) putchar('0' | st[tp--]);
  putchar(c);
}
template <class T>
inline void err(const T &x, const char c = '\n') {
  cerr << x << c;
}
template <class T, class... Args>
inline void err(const T &x, const Args &...args) {
  err(x, ' '), err(args...);
}
const int md = 998244353;
inline int qpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = (long long)a * a % md)
    if (b & 1) r = (long long)r * a % md;
  return r;
}
inline int fit(const int x) { return x >= md ? x - md : x; }
inline void inc(int &x, const int v) { (x += v) >= md ? x -= md : 0; }
namespace i207M {
const int N = 1005;
void sft(char s[], int len, int k) {
  for (int i = len; i >= 1; --i) s[i + k] = s[i];
  for (int i = 1; i <= k; ++i) s[i] = 0;
}
int n, len;
int id[N];
char A[N], B[N][N];
int la, lb[N];
int dp[N][N];
int c[10];
int jin, val;
inline void add(int w, int op) {
  if (w >= 10)
    val += op * c[w - 10], jin += op;
  else
    val += op * c[w];
}
signed main() {
  scanf("%s", A + 1);
  la = strlen(A + 1), len = max(len, la);
  in(n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", B[i] + 1);
    lb[i] = strlen(B[i] + 1);
    len = max(len, lb[i]);
  }
  for (int i = 0; i <= 9; ++i) in(c[i]);
  ++len;
  sft(A, la, len - la);
  for (int i = 1; i <= n; ++i) sft(B[i], lb[i], len - lb[i]);
  memset(dp, 0xcf, sizeof(dp));
  const int ninf = dp[0][0];
  dp[len + 1][0] = 0;
  for (int i = 1; i <= n; ++i) id[i] = i;
  for (int i = len; i >= 1; --i) {
    for (int k = (A[i] == '?' ? (A[i - 1] ? 0 : 1) : A[i] - '0'),
             mk = (A[i] == '?' ? 9 : A[i] - '0');
         k <= mk; ++k) {
      jin = val = 0;
      for (int j = 1, w; j <= n; ++j) {
        w = B[j][i] - '0';
        if (w >= 0)
          add(w + max(k, 0), 1);
        else if (k >= 0)
          add(k, 1);
      }
      for (int j = 0, w; j <= n; ++j) {
        if (j) {
          w = B[id[j]][i] - '0';
          if (w >= 0) {
            add(w + max(k, 0), -1);
            add(w + max(k, 0) + 1, 1);
          } else if (k >= 0)
            add(k, -1), add(k + 1, 1);
          else
            add(1, 1);
        }
        if (dp[i + 1][j] < 0) continue;
        dp[i][jin] = max(dp[i][jin], dp[i + 1][j] + val);
      }
    }
    stable_sort(id + 1, id + 1 + n, [i](const int a, const int b) {
      return max(B[a][i], '0') > max(B[b][i], '0');
    });
  }
  int ans = ninf;
  for (int i = 0; i <= n; ++i) ans = max(ans, dp[1][i]);
  out(ans);
  return 0;
}
}  // namespace i207M
signed main() {
  i207M::main();
  return 0;
}