#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 1010, maxm = 1010;
int an;
int n;
int a[maxm + 5];
int b[maxn + 5][maxm + 5];
int len[maxn + 5];
int dp[maxm + 5][maxn + 5];
int cost[10];
int pos[maxn + 5], ppos[maxn + 5];
int main() {
  static char s[maxm + 5];
  scanf("%s", s);
  an = strlen(s);
  reverse(s, s + an);
  for (int i = (0), i_end_ = (an); i < i_end_; ++i) {
    if (s[i] == '?')
      a[i] = -1;
    else
      a[i] = s[i] - '0';
  }
  scanf("%d", &n);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    scanf("%s", s);
    len[i] = strlen(s);
    reverse(s, s + len[i]);
    for (int j = (0), j_end_ = (len[i]); j < j_end_; ++j) b[i][j] = s[j] - '0';
  }
  for (int i = (0), i_end_ = (10); i < i_end_; ++i) scanf("%d", cost + i);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) pos[i] = i;
  memset(dp, -oo, sizeof dp);
  dp[0][0] = 0;
  for (int i = (0), i_end_ = (maxm); i < i_end_; ++i) {
    static int dcnt[11];
    memset(dcnt, 0, sizeof dcnt);
    for (int j = (0), j_end_ = (n); j < j_end_; ++j)
      if (i < an || i < len[j]) ++dcnt[b[j][i]];
    for (int j = (0), j_end_ = (n + 1); j < j_end_; ++j) {
      if (dp[i][j] >= 0) {
        for (int k = (0), k_end_ = (10); k < k_end_; ++k) {
          if (i >= an && k) continue;
          if (i == an - 1 && !k) continue;
          if (i < an && ~a[i] && k != a[i]) continue;
          int delta = 0;
          int carry = 0;
          for (int l = (0), l_end_ = (11); l < l_end_; ++l)
            if (dcnt[l])
              delta += dcnt[l] * cost[(l + k) % 10],
                  carry += (l + k >= 10) * dcnt[l];
          chkmax(dp[i + 1][carry], dp[i][j] + delta);
        }
      }
      if (j < n) {
        if (i < an || i < len[pos[j]]) --dcnt[b[pos[j]][i]];
        ++dcnt[b[pos[j]][i] + 1];
      }
    }
    static int sum[10];
    memset(sum, 0, sizeof sum);
    for (int j = (0), j_end_ = (n); j < j_end_; ++j) ++sum[b[j][i]];
    for (int j = 9; j >= 1; --j) sum[j - 1] += sum[j];
    for (int j = n - 1; j >= 0; --j) ppos[--sum[b[pos[j]][i]]] = pos[j];
    memcpy(pos, ppos, sizeof pos);
  }
  printf("%d\n", dp[maxm][0]);
  return 0;
}
