#include <bits/stdc++.h>
const int inf = 1e9;
std::string b[1010];
std::string s;
int f[1010][1010], h[1010][1010][12], g[1010][1010][12], rank[1010][1010],
    sa[1010], len[1010];
int L, n, tmp_d, cost[20];
void rlxx(int &x, int y) {
  if (x < y) x = y;
}
void trans(int i, int c) {
  for (int k = 1; k <= n + 1; ++k)
    if (f[i][k] != -inf) {
      int up = g[i][k][10 - c - 1] + g[i][1][10 - c] - g[i][k][10 - c];
      rlxx(f[i + 1][n + 1 - up],
           f[i][k] + h[i][k][c + 1] + h[i][1][c] - h[i][k][c]);
    }
}
bool cmp(int i, int j) {
  return b[i][tmp_d] != b[j][tmp_d] ? b[i][tmp_d] < b[j][tmp_d]
                                    : rank[tmp_d][i] < rank[tmp_d][j];
}
int main() {
  std::cin >> s;
  int ls = s.size();
  L = ls;
  std::reverse(s.begin(), s.end());
  std::cin >> n;
  for (int i = 1; i <= n; ++i) {
    std::cin >> b[i];
    len[i] = b[i].size();
    std::reverse(b[i].begin(), b[i].end());
    while (b[i].back() == '0') b[i].pop_back();
    L = std::max(len[i], L);
  }
  for (int i = 0; i < 10; ++i) std::cin >> cost[i];
  ++L;
  for (int i = 1; i <= n; ++i)
    for (int k = len[i]; k <= L - 1; ++k) b[i].push_back('0');
  for (int i = 1; i <= n; ++i) rank[0][i] = 1;
  for (int d = 0; d < L; ++d) {
    tmp_d = d;
    for (int i = 1; i <= n; ++i) sa[i] = i;
    std::sort(sa + 1, sa + n + 1, cmp);
    int sz = 0;
    for (int i = 1; i <= n; ++i) {
      rank[d + 1][sa[i]] = i;
    }
    for (int i = 1; i <= n; ++i)
      for (int c = 0; c < 11; ++c) {
        if (d < len[i] || d < ls || c > 0)
          h[d][rank[d][i]][c] += cost[(b[i][d] - '0' + c) % 10];
        g[d][rank[d][i]][c] += (b[i][d] - '0' >= c);
      }
    for (int i = n; i >= 1; --i)
      for (int c = 0; c < 11; ++c) {
        h[d][i][c] += h[d][i + 1][c];
        g[d][i][c] += g[d][i + 1][c];
      }
  }
  int head = s.size();
  for (int i = head; i <= L - 1; ++i) s.push_back('0');
  for (int i = 0; i < L + 1; ++i)
    for (int k = 1; k <= n + 1; ++k) f[i][k] = -inf;
  f[0][n + 1] = 0;
  for (int i = 0; i < L; ++i) {
    if (s[i] != '?') {
      int d = s[i] - '0';
      trans(i, d);
    } else {
      for (int d = 0; d < 10; ++d) {
        if (i + 1 == head && d == 0) continue;
        trans(i, d);
      }
    }
  }
  printf("%d\n", f[L][n + 1]);
  return 0;
}
