#include <bits/stdc++.h>
using namespace std;
int const M = 1000 + 10, M2 = 1e3 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
string y[M], x;
int dp[M][M], val[M], ran[M][M], now, st[M], f[M][10], ind[M], n, bad,
    ind2[M][M], siz[M], carry[M];
int last[10], cnt[10];
bool cmp(int a, int b) {
  if (y[a][now] != y[b][now]) return (y[a][now] - '0') < (y[b][now] - '0');
  if (now == 0) return a < b;
  return ran[now - 1][a] < ran[now - 1][b];
}
void ch(int i, int j, int k) {
  int ans = 0, sv = n + 1;
  for (int t = 0; t <= 9; t++) {
    if (st[t] == -1) continue;
    int l = st[t], r = last[t] + 1;
    if (f[j][t] != -1 && f[j][t] <= last[t] && f[j][t] >= st[t]) r = f[j][t];
    ans += (r - l) * val[((k + t) % 10)];
    ans += (last[t] + 1 - r) * val[(k + t + 1) % 10];
    if (k + t == 9) {
      if (r != last[t] + 1) sv = r;
    }
  }
  for (int l = 9 - k + 1; l <= 9; l++) {
    if ((sv == n + 1 || sv == -1) && st[l] != -1) sv = st[l];
  }
  ans += dp[i + 1][sv];
  dp[i][j] = max(ans, dp[i][j]);
}
void fdp(int i, int j) {
  if (j == 1) {
    for (int k = 0; k <= 9; k++) last[k] = -1, cnt[k] = 0, st[k] = -1;
    for (int k = 1; k <= n; k++) {
      last[y[k][i] - '0'] = max(ran[i][k], last[y[k][i] - '0']);
      if (st[y[k][i] - '0'] == -1 || ran[i][k] < st[y[k][i] - '0'])
        st[y[k][i] - '0'] = ran[i][k];
    }
    for (int k = 0; k <= 9; k++) {
      for (int l = 1; l <= n + 1; l++) {
        f[l][k] = -1;
      }
      int pnt = st[k];
      for (int l = 1; l <= n + 1; l++) {
        if (last[k] == -1 || i == 0) {
          continue;
        }
        while (ran[i - 1][ind2[i][pnt]] < l && pnt != last[k] + 1) pnt++;
        f[l][k] = pnt;
      }
    }
  }
  if (x[i] == '?') {
    int s = 0;
    if (i == bad) s = 1;
    for (int k = s; k <= 9; k++) ch(i, j, k);
  } else
    ch(i, j, x[i] - '0');
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> x;
  reverse(x.begin(), x.end());
  bad = (int)x.size() - 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> y[i];
    siz[i] = y[i].size();
    reverse(y[i].begin(), y[i].end());
    while (y[i].size() < 1001) y[i] += '0';
  }
  for (int i = 0; i <= 9; i++) cin >> val[i];
  for (int i = 0; i <= 1000; i++) {
    now = i;
    for (int j = 1; j <= n; j++) {
      ind[j] = j;
    }
    sort(ind + 1, ind + n + 1, cmp);
    for (int j = 1; j <= n; j++) {
      ran[i][ind[j]] = j;
      ind2[i][j] = ind[j];
    }
  }
  for (int j = n + 1; j >= 1; j--) {
    int t = x.size();
    for (int k = j; k <= n; k++) {
      int id = ind2[t - 1][k];
      dp[t][j] += val[(y[id][t] - '0' + 1) % 10];
      if (y[id][t] - '0' == 9) carry[id] = 1;
    }
    for (int i = 1; i <= j - 1; i++) {
      int id = ind2[t - 1][i];
      if (siz[id] > x.size()) dp[t][j] += val[y[id][t] - '0'];
    }
    for (int k = 1; k <= n; k++) {
      for (int l = t + 1; l < siz[k]; l++) {
        dp[t][j] += val[((y[k][l] - '0' + carry[k]) % 10)];
        if (y[k][l] - '0' == 9 && carry[k])
          carry[k] = 1;
        else
          carry[k] = 0;
      }
      if (carry[k]) dp[t][j] += val[1];
      carry[k] = 0;
    }
  }
  for (int i = (int)x.size() - 1; i >= 0; i--) {
    for (int j = 1; j <= n + 1; j++) {
      fdp(i, j);
    }
  }
  cout << dp[0][n + 1];
}
