#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 1005;
int n, f[2][maxn], id[maxn], tid[maxn], suf[maxn];
int cnt[11], val[11];
char B[maxn][maxn], A[maxn];
void radix_sort(int dig) {
  memset(cnt, 0, sizeof cnt);
  for (int i = int(1); i <= (int)(n); i++) cnt[B[i][dig] - '0']++;
  for (int i = int(8); i >= (int)(0); i--) cnt[i] += cnt[i + 1];
  for (int i = int(n); i >= (int)(1); i--)
    tid[cnt[B[id[i]][dig] - '0']--] = id[i];
}
int ml = 0, Al, l, jw[maxn];
void upd(int &x, int y) {
  if (y > x) x = y;
}
int calc(int i) {
  int lst = ml + 1, ret = 0;
  while (B[i][lst] == '0') lst--;
  for (int j = int(Al + 1); j <= (int)(lst); j++) ret += val[B[i][j] - '0'];
  return ret;
}
int main() {
  scanf("%s", A + 1);
  Al = strlen(A + 1);
  ml = max(ml, Al);
  reverse(A + 1, A + Al + 1);
  n = rd();
  for (int i = int(1); i <= (int)(n); i++) id[i] = i;
  for (int i = int(1); i <= (int)(n); i++) {
    scanf("%s", B[i] + 1);
    l = strlen(B[i] + 1);
    ml = max(ml, l);
    reverse(B[i] + 1, B[i] + l + 1);
  }
  for (int i = int(0); i <= (int)(9); i++) val[i] = rd();
  for (int j = int(1); j <= (int)(ml + 1); j++)
    if (!A[j]) A[j] = '0';
  for (int i = int(1); i <= (int)(n); i++)
    for (int j = int(1); j <= (int)(ml + 1); j++)
      if (!B[i][j]) B[i][j] = '0';
  int fr = 0, go = 1;
  memset(f[fr], -1, sizeof f[fr]);
  f[fr][0] = 0;
  for (int d = int(1); d <= (int)(Al); d++) {
    radix_sort(d);
    memset(f[go], -1, sizeof f[go]);
    int sum = 0, nxt = 0;
    for (int x = int(0); x <= (int)(9); x++)
      if (A[d] == '?' || A[d] == '0' + x) {
        if (d == Al && x == 0) continue;
        while (nxt < n && B[tid[nxt + 1]][d] - '0' + x >= 10) nxt++;
        memset(jw, 0, sizeof jw);
        sum = 0;
        for (int i = int(1); i <= (int)(n); i++)
          sum += val[(B[i][d] - '0' + x) % 10];
        for (int i = int(0); i <= (int)(n); i++) {
          if (i) {
            jw[id[i]] = 1;
            int yl = (B[id[i]][d] - '0' + x) % 10;
            sum -= val[yl], sum += val[(yl + 1) % 10];
            while (nxt < n &&
                   B[tid[nxt + 1]][d] - '0' + x + jw[tid[nxt + 1]] >= 10)
              nxt++;
          }
          if (~f[fr][i]) upd(f[go][nxt], f[fr][i] + sum);
        }
      }
    fr ^= 1, go ^= 1;
    memcpy(id, tid, sizeof tid);
  }
  int ans = 0, sum = 0;
  for (int i = int(0); i <= (int)(n); i++) sum += calc(i);
  for (int i = int(0); i <= (int)(n); i++) {
    if (i) {
      int _i = id[i];
      sum -= calc(_i);
      B[_i][Al + 1]++;
      for (int j = Al + 1; B[_i][j] - '0' >= 10; j++)
        B[_i][j] -= 10, B[_i][j + 1]++;
      sum += calc(_i);
    }
    if (~f[fr][i]) upd(ans, f[fr][i] + sum);
  }
  rt(ans), putchar('\n');
}
