#include <bits/stdc++.h>
using namespace std;
void getre() {
  int x = 0;
  printf("%d\n", 1 / x);
}
void gettle() {
  int res = 1;
  while (1) res <<= 1;
  printf("%d\n", res);
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
template <typename N>
inline int sgn(N a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gs(char *s) { scanf("%s", s); }
inline void gc(char &c) {
  while ((c = getchar()) > 126 || c < 33)
    ;
}
inline void pc(char c) { putchar(c); }
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846264338327950288L;
const double eps = 1e-6;
char stradd[1111];
int canaddl[1111], canaddr[1111];
int lenl[1111], lenr[1111];
int n;
int a[1111][1111];
char str[1111];
int cost[10];
int l = 1005;
int f[1111][1111];
int sa[1111];
int pos[1111];
inline int co(int i, int ch, int pos) {
  if (ch != 0) return cost[ch];
  if (pos >= lenr[i]) return 0;
  return cost[0];
}
int curpos;
int cmp(int i, int j) {
  if (a[i][curpos] != a[j][curpos])
    return a[i][curpos] > a[j][curpos];
  else
    return pos[i] < pos[j];
}
int main() {
  gs(stradd);
  int len = strlen(stradd);
  for (int i = (0), _ed = (len); i < _ed; i++) {
    int pos = len - i;
    if (i == 0 && stradd[i] == '?') {
      canaddl[pos] = 1;
      canaddr[pos] = 9;
    } else if (stradd[i] == '?') {
      canaddl[pos] = 0;
      canaddr[pos] = 9;
    } else {
      canaddl[pos] = stradd[i] - '0';
      canaddr[pos] = stradd[i] - '0';
    }
  }
  gn(n);
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    gs(str);
    int le = strlen(str);
    for (int j = (0), _ed = (le); j < _ed; j++) a[i][le - j] = str[j] - '0';
    lenl[i] = max(le, len);
    lenr[i] = max(le, len) + 1;
  }
  for (int i = (0), _ed = (10); i < _ed; i++) gn(cost[i]);
  memset((f), (-64), sizeof(f));
  f[0][0] = 0;
  for (int i = (1), _ed = (n + 1); i < _ed; i++) sa[i] = i;
  for (int i = (1), _ed = (l + 1); i < _ed; i++) {
    for (int ad = (canaddl[i]), _ed = (canaddr[i] + 1); ad < _ed; ad++) {
      int jin = 0;
      int su = 0;
      for (int j = (1), _ed = (n + 1); j < _ed; j++) {
        int x = a[j][i];
        su += co(j, (ad + x) % 10, i);
        if (ad + x >= 10) jin++;
      }
      int cur = 1;
      for (int t = (0), _ed = (n + 1); t < _ed; t++) {
        if (t) {
          int j = sa[t];
          int x = a[j][i];
          su -= co(j, (ad + x) % 10, i);
          su += co(j, (ad + x + 1) % 10, i);
          if (ad + x + 1 == 10) jin++;
        }
        if (su + f[i - 1][t] >= 0) upmax(f[i][jin], su + f[i - 1][t]);
      }
    }
    for (int t = (1), _ed = (n + 1); t < _ed; t++) pos[sa[t]] = t;
    curpos = i;
    sort(sa + 1, sa + 1 + n, cmp);
  }
  printf("%d\n", f[l][0]);
  return 0;
}
