#include <bits/stdc++.h>
using namespace std;
char s[1300];
char t[1300][1300];
int f[1300][1300];
int len[1300], maxx, n;
vector<int> v[1300][1300];
int a[13], pp[1300];
int nn[1300], ll;
int cc(char x, int d, int b, int c) {
  if (x == '-' && d == 0 && b >= c)
    return 0;
  else if (x == '-')
    return a[d % 10];
  else
    return a[(x - '0' + d) % 10];
}
struct node {
  int x, y, z;
} pl[1100];
int cmp(node a, node b) {
  if (a.y != b.y)
    return a.y > b.y;
  else
    return a.x < b.x;
}
int main() {
  memset(f, -1, sizeof(f));
  scanf("%s", s);
  maxx = ll = strlen(s);
  reverse(s, s + maxx);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%s", t[i]), len[i] = strlen(t[i]), maxx = max(maxx, len[i]),
                       reverse(t[i], t[i] + len[i]);
  maxx += 200;
  for (int i = strlen(s); i < maxx; i++) s[i] = '0';
  for (int i = 1; i <= n; i++)
    for (int j = len[i]; j < maxx; j++) t[i][j] = '-';
  for (int i = 0; i < 10; i++) scanf("%d", &a[i]);
  f[0][0] = 0;
  for (int i = 1; i <= n; i++) v[0][1].push_back(i);
  for (int i = 0; i < maxx; i++) {
    for (int j = 0; j <= 9; j++) {
      if (s[i] != '?' && s[i] != j + '0') continue;
      if (i == ll - 1 && j == 0) continue;
      memset(pp, 0, sizeof(pp));
      int ans = 0, nu = 0;
      for (int k = 1; k <= n; k++) {
        ans += cc(t[k][i], j, i, ll);
        if ((t[k][i] == '-' ? '0' : t[k][i]) - '0' + j > 9) pp[k] = 1, nu++;
      }
      for (int k = 0; k <= n; k++) {
        for (int l = 0; l < v[i][k].size(); l++) {
          ans -= cc(t[v[i][k][l]][i], j, i, ll);
          ans += cc(t[v[i][k][l]][i], j + 1, i, ll);
          if ((t[v[i][k][l]][i] == '-' ? '0' : t[v[i][k][l]][i]) - '0' + j + 1 >
                  9 &&
              !pp[v[i][k][l]])
            pp[v[i][k][l]] = 1, nu++;
        }
        if (f[i][k] == -1) continue;
        f[i + 1][nu] = max(f[i + 1][nu], f[i][k] + ans);
      }
    }
    for (int j = 1; j <= n; j++)
      pl[j].x = nn[j], pl[j].y = (t[j][i] == '-' ? '0' : t[j][i]) - '0',
      pl[j].z = j;
    sort(pl + 1, pl + 1 + n, cmp);
    pl[n + 1].x = -1;
    for (int j = n; j >= 1; j--)
      if (pl[j].x == pl[j + 1].x && pl[j].y == pl[j + 1].y)
        nn[pl[j].z] = nn[pl[j + 1].z];
      else
        nn[pl[j].z] = j;
    for (int j = 1; j <= n; j++) v[i + 1][nn[j]].push_back(j);
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, f[maxx][i]);
  cout << ans << endl;
  return 0;
}
