#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 3;
int a[N], m[N], b[N][N], v[10], id[N * 10], nxt[N * 10], sr[N * 10][10],
    sl[N * 10][10], dp[N][N];
vector<int> vec[N], vec2[N * 10];
int main() {
  static char s[N], t[N];
  int n;
  scanf("%s%d", s, &n);
  int l = strlen(s);
  for (int j = 1; j <= l; ++j) a[j] = s[l - j] == '?' ? -1 : s[l - j] - '0';
  while (l && a[l] == 0) --l;
  int lm = l;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", t);
    m[i] = strlen(t);
    for (int j = 1; j <= m[i]; ++j) b[i][j] = t[m[i] - j] - '0';
    while (m[i] && b[i][m[i]] == 0) --m[i];
    lm = max(lm, m[i]);
  }
  for (int i = 0; i <= 9; ++i) scanf("%d", &v[i]);
  for (int i = 1; i <= n; ++i) vec[1].push_back(i);
  int cnt = 2;
  for (int i = 0; i <= lm + 1; ++i)
    for (int j = 1; j <= n + 1; ++j) dp[i][j] = -1e9;
  dp[0][1] = -1e9, dp[0][2] = 0;
  for (int i = 0; i <= lm; ++i) {
    for (int t = 0; t <= 9; ++t) sr[cnt + 1][t] = 0;
    for (int j = cnt; j >= 1; --j) {
      for (int t = 0; t <= 9; ++t) sr[j][t] = sr[j + 1][t];
      for (int k = 0, kend = vec[j].size(); k < kend; ++k) {
        int p = vec[j][k];
        for (int t = 0; t <= 9; ++t) {
          if (i + 1 > max(l, m[p]) + 1) continue;
          int u = ((b[p][i + 1] + t + 1) >= 10 ? (b[p][i + 1] + t + 1) - 10
                                               : (b[p][i + 1] + t + 1));
          sr[j][t] += i + 1 <= max(l, m[p]) || u ? v[u] : 0;
        }
      }
    }
    for (int j = 1; j <= cnt; ++j) {
      for (int t = 0; t <= 9; ++t) sl[j][t] = sl[j - 1][t];
      for (int k = 0, kend = vec[j].size(); k < kend; ++k) {
        int p = vec[j][k];
        for (int t = 0; t <= 9; ++t) {
          if (i + 1 > max(l, m[p]) + 1) continue;
          int u = ((b[p][i + 1] + t) >= 10 ? (b[p][i + 1] + t) - 10
                                           : (b[p][i + 1] + t));
          sl[j][t] += i + 1 <= max(l, m[p]) || u ? v[u] : 0;
        }
      }
    }
    for (int j = 1; j <= cnt * 10; ++j) vec2[j].clear(), id[j] = 0;
    for (int j = 1; j <= cnt; ++j)
      for (int k = 0, kend = vec[j].size(); k < kend; ++k) {
        int p = vec[j][k];
        vec2[b[p][i + 1] * cnt + j].push_back(p);
      }
    int cnt2 = 0;
    for (int j = 1; j <= cnt * 10; ++j)
      if (vec2[j].size()) id[j] = ++cnt2;
    nxt[cnt * 10 + 1] = cnt2 + 1;
    for (int j = cnt * 10; j >= 1; --j)
      nxt[j] = vec2[j].size() ? id[j] : nxt[j + 1];
    for (int j = 1; j <= cnt; ++j) {
      int b = 0, e = 9;
      if (i + 1 > l)
        b = e = 0;
      else if (~a[i + 1])
        b = e = a[i + 1];
      else if (i + 1 == l)
        b = 1;
      for (int t = b; t <= e; ++t) {
        int &x = dp[i + 1][nxt[cnt * (9 - t) + j]];
        x = max(x, dp[i][j] + sr[j][t] + sl[j - 1][t]);
      }
    }
    for (int j = 1; j <= cnt2 + 1; ++j) vec[j].clear();
    for (int j = 1; j <= cnt * 10; ++j)
      if (id[j]) vec[id[j]] = vec2[j];
    cnt = cnt2 + 1;
  }
  int ans = 0;
  for (int j = 1; j <= cnt; ++j) ans = max(ans, dp[lm + 1][j]);
  printf("%d\n", ans);
  return 0;
}
