#include <bits/stdc++.h>
using namespace std;
struct node {
  int y, nex;
} e[1100];
int n, m, a[1100], b[1100][1100], c[10], f[1100][1100], sa1[1100], sa2[1100],
    pos[10], fir[10];
int len, rk[1100], w[1100], g[10], ap, mx[1100];
char s[1100][1100];
void init() {
  scanf("%s", s[0] + 1);
  m = strlen(s[0] + 1);
  int maxd = m;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    int t = strlen(s[i] + 1);
    m = max(m, t);
  }
  m++;
  int t = strlen(s[0] + 1);
  for (int i = 1; i <= t; i++)
    if (s[0][i] != '?')
      a[i + m - t] = s[0][i] - '0';
    else
      a[i + m - t] = -1;
  if (s[0][1] == '?')
    ap = 1 + m - t;
  else
    ap = -1;
  for (int i = 1; i <= n; i++) {
    t = strlen(s[i] + 1);
    mx[i] = max(maxd, t);
    for (int j = 1; j <= t; j++) b[i][j + m - t] = s[i][j] - '0';
  }
  for (int i = 1; i <= m / 2; i++) swap(a[i], a[m - i + 1]);
  if (ap != -1) ap = m - ap + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m / 2; j++) swap(b[i][j], b[i][m - j + 1]);
  for (int i = 0; i <= 9; i++) scanf("%d", &c[i]);
}
void upd(int &x, int y) {
  if (y > x) x = y;
}
void ins(int x, int y) {
  e[++len].y = y;
  e[len].nex = fir[x];
  fir[x] = len;
}
void make_sa(int k) {
  for (int i = 0; i <= 9; i++) fir[i] = 0;
  len = 0;
  for (int i = 1; i <= n; i++) ins(b[sa1[i]][k], sa1[i]);
  int num = n;
  for (int x = 0; x <= 9; x++)
    for (int k = fir[x]; k; k = e[k].nex) {
      int y = e[k].y;
      sa2[num--] = y;
    }
  for (int i = 1; i <= n; i++) rk[sa2[i]] = i;
}
void solve() {
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= n; j++) f[i][j] = -1;
  for (int i = 1; i <= n; i++) sa1[i] = i;
  f[0][0] = 0;
  for (int i = 0; i < m; i++) {
    make_sa(i + 1);
    for (int j = 1; j <= n; j++) w[j] = b[sa2[j]][i + 1];
    for (int j = 0; j <= 9; j++) {
      g[j] = 0;
      for (int k = 1; k <= n; k++)
        if (mx[sa2[k]] >= i + 1) g[j] += c[(w[k] + j) % 10];
    }
    for (int j = 0; j <= 9; j++) pos[j] = 0;
    int st = 0, ed = 9;
    if (a[i + 1] != -1)
      st = ed = a[i + 1];
    else if (i + 1 == ap)
      st = 1;
    int j1 = 0;
    for (int j = 0; j <= n; j++) {
      if (f[i][j] == -1) continue;
      while (j1 < j) {
        j1++;
        int t = w[rk[sa1[j1]]];
        w[rk[sa1[j1]]]++;
        for (int k = st; k <= ed; k++)
          if (mx[sa1[j1]] >= i + 1) g[k] -= c[(t + k) % 10];
        t++;
        for (int k = st; k <= ed; k++) g[k] += c[(t + k) % 10];
      }
      for (int k = st; k <= ed; k++) {
        while (pos[k] < n && w[pos[k] + 1] + k >= 10) pos[k]++;
        upd(f[i + 1][pos[k]], f[i][j] + g[k]);
      }
    }
    for (int i = 1; i <= n; i++) sa1[i] = sa2[i];
  }
  printf("%d\n", f[m][0]);
}
int main() {
  init();
  solve();
  return 0;
}
