#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
struct num {
  int x[N], sz;
  friend istream &operator>>(istream &get, num &n) {
    string s;
    get >> s, n.sz = s.size();
    for (int i = 0; i < n.sz; i++)
      n.x[n.sz - i - 1] = (s[i] ^ '?' ? s[i] - '0' : -1);
    return get;
  }
} a, b[N];
int n, m, c[10], id[N], dp[N][N];
int main() {
  cin >> a >> n, m = a.sz + 1;
  for (int i = 0; i < n; i++) {
    cin >> b[id[i] = i];
    m = max(m, b[i].sz + 1);
  }
  for (int i = 0; i < 10; i++) cin >> c[i];
  memset(dp, -63, sizeof dp);
  for (int p = dp[0][0] = 0; p < m; p++) {
    for (int r = 9, l = (~a.x[p] ? r = a.x[p] : p + 1 >= a.sz), k = l; k <= r;
         k++) {
      int ten = 0, cost = 0;
      for (int i = 0; i < n; i++) {
        int w = b[i].x[p] + k;
        cost += max(a.sz, b[i].sz) > p || w ? c[w % 10] : 0, ten += w > 9;
      }
      for (int i = 0; i <= n; i++) {
        int w = b[id[i]].x[p] + k;
        dp[p + 1][ten] = max(dp[p + 1][ten], dp[p][i] + cost);
        cost +=
            c[(w + 1) % 10] - (max(a.sz, b[id[i]].sz) > p || w ? c[w % 10] : 0),
            ten += w < 9 ? 0 : w == 9;
      }
    }
    stable_sort(id, id + n,
                [p](int i, int j) { return b[i].x[p] > b[j].x[p]; });
  }
  cout << dp[m][0];
}
