#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
char s[maxn], tmp[maxn];
int x[maxn][maxn], f[maxn][maxn];
int len[maxn];
int rk[maxn][maxn], sa[maxn][maxn];
int v[maxn];
int c[11];
int n, m, l;
void sort() {
  for (int i = 1; i <= n; ++i) sa[0][i] = i;
  for (int i = 1; i <= m; ++i) {
    memset(v, 0, sizeof(v));
    for (int j = 1; j <= n; ++j) v[x[j][i]]++;
    for (int j = 8; j >= 0; --j) v[j] += v[j + 1];
    for (int j = n; j >= 1; --j) rk[i][sa[i - 1][j]] = v[x[sa[i - 1][j]][i]]--;
    for (int j = 1; j <= n; ++j) sa[i][rk[i][j]] = j;
  }
}
int upd, num;
int work(int k, int d) {
  int _n = n, ret = 0;
  for (int i = 1; i <= n; ++i) {
    int j = sa[k][i], y = x[j][k] + d;
    if (_n == n && y < 10) _n = i - 1;
    if (l < k && len[j] < k && !y) continue;
    ret += c[y % 10], upd += y >= 10;
  }
  if (f[k - 1][0] >= 0) f[k][upd] = max(f[k][upd], f[k - 1][0] + ret);
  return ret;
}
void solve(int i, int j, int d) {
  int y = x[j][i] + d;
  num += c[(y + 1) % 10] - c[y % 10];
  if (l < i && len[j] < i && !y) num += c[y % 10];
  upd += (y == 9);
}
int t;
int main() {
  m = 1000;
  scanf("%s", tmp);
  l = strlen(tmp);
  for (int i = 1; i <= l; ++i) s[i] = tmp[l - i];
  for (int i = l + 1; i <= m; ++i) s[i] = '0';
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", tmp);
    len[i] = strlen(tmp);
    for (int j = 1; j <= len[i]; ++j) x[i][j] = tmp[len[i] - j] - '0';
  }
  sort();
  for (int i = 0; i <= 9; ++i) scanf("%d", &c[i]);
  memset(f, -1, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= m; ++i) {
    if (s[i] == '?') {
      for (int d = 0; d <= 9; ++d) {
        if (i == l && !d) continue;
        upd = 0, num = work(i, d), ++t;
        for (int j = 1; j <= n; ++j) {
          solve(i, sa[i - 1][j], d);
          if (f[i - 1][j] >= 0) f[i][upd] = max(f[i][upd], f[i - 1][j] + num);
        }
      }
    } else {
      int d = s[i] - '0';
      upd = 0, num = work(i, d);
      for (int j = 1; j <= n; ++j) {
        solve(i, sa[i - 1][j], d);
        if (f[i - 1][j] >= 0) f[i][upd] = max(f[i][upd], f[i - 1][j] + num);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) ans = max(ans, f[m][i] + i * c[1]);
  printf("%d\n", ans);
}
