#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
template <typename T>
inline void cmax(T &x, T y) {
  if (x < y) x = y;
}
char s[N];
int len, n, m[N], mx, A[N], B[N][N], cost[10];
int cnt[10], rnk[N], rk2[N], dp[N][N];
void init() {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  mx = len;
  for (int i = 1; i <= len; ++i) {
    A[i] = s[len - i + 1] - '0';
  }
  read(n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    m[i] = strlen(s + 1);
    cmax(mx, m[i]);
    for (int j = 1; j <= m[i]; ++j) {
      B[i][j] = s[m[i] - j + 1] - '0';
    }
  }
  ++mx;
  for (int i = 0; i <= 9; ++i) {
    read(cost[i]);
  }
}
void solve() {
  for (int i = 1; i <= n; ++i) {
    rnk[i] = i;
  }
  memset(dp, 0x80, sizeof(dp));
  dp[0][0] = 0;
  for (int d = 1, l, r; d <= mx; ++d) {
    if (A[d] <= 9) {
      l = r = A[d];
    } else {
      l = (d == len ? 1 : 0);
      r = 9;
    }
    for (int k = l; k <= r; ++k) {
      int sum = 0, jin = 0;
      for (int i = 1; i <= n; ++i) {
        int cur = k + B[i][d];
        if (!cur) {
          if (d <= m[i] || d <= len) {
            sum += cost[0];
          }
        } else if (cur > 9) {
          sum += cost[cur - 10];
          ++jin;
        } else {
          sum += cost[cur];
        }
      }
      for (int i = 0; i <= n; ++i) {
        if (i) {
          int cur = k + B[rnk[n - i + 1]][d];
          if (cur == 9) {
            sum += cost[0] - cost[9];
            ++jin;
          } else {
            if (cur == 0 && d > m[rnk[n - i + 1]] && d > len) {
              sum += cost[1];
            } else {
              sum += cost[cur % 10 + 1] - cost[cur % 10];
            }
          }
        }
        cmax(dp[d][jin], dp[d - 1][i] + sum);
      }
    }
    for (int i = 0; i <= 9; ++i) {
      cnt[i] = 0;
    }
    for (int i = 1; i <= n; ++i) {
      ++cnt[B[i][d]];
    }
    for (int i = 1; i <= 9; ++i) {
      cnt[i] += cnt[i - 1];
    }
    for (int i = n; i >= 1; --i) {
      rk2[cnt[B[rnk[i]][d]]--] = rnk[i];
    }
    memcpy(rnk, rk2, sizeof(rnk));
  }
  printf("%d\n", dp[mx][0]);
}
int main() {
  init();
  solve();
  return 0;
}
