#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int dp[N][N], n, m, k;
int f[N], g[N], a[N], lth[N], b[N][N], cnt[10], val[10];
char s[N];
void sort(int x) {
  for (int i = 0; i < 10; i++) cnt[i] = 0;
  for (int i = 1; i <= m; i++) cnt[b[i][x]]++;
  for (int i = 1; i < 10; i++) cnt[i] += cnt[i - 1];
  for (int i = m; i >= 1; i--) g[cnt[b[f[i]][x]]--] = f[i];
  memcpy(f, g, sizeof(g));
}
void solve(int x) {
  int l = 0, r = 9;
  if (a[x] <= 9)
    l = r = a[x];
  else if (x == n)
    l = 1;
  for (int i = l; i <= r; i++) {
    int sum = 0, s = 0;
    for (int j = 1; j <= m; j++) {
      int o = i + b[j][x];
      if (!o) {
        if (x <= lth[j] || x <= n) sum += val[0];
      } else if (o >= 10)
        sum += val[o - 10], s++;
      else
        sum += val[o];
    }
    for (int j = m; j >= 0; j--) {
      if (j < m) {
        int tmp = f[j + 1], o = i + b[tmp][x];
        if (o != 9) {
          if (!o && x > n && x > lth[tmp])
            sum += val[1];
          else
            sum += val[o % 10 + 1] - val[o % 10];
        } else
          sum += val[0] - val[9], s++;
      }
      dp[x][m - s] = max(dp[x][m - s], dp[x - 1][j] + sum);
    }
  }
}
int main() {
  scanf("%s", s);
  n = k = strlen(s);
  for (int i = 1; i <= n; i++) a[i] = s[n - i] - '0';
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s", s);
    lth[i] = strlen(s);
    k = max(k, lth[i]);
    for (int j = 1; j <= lth[i]; j++) b[i][j] = s[lth[i] - j] - '0';
    f[i] = i;
  }
  for (int i = 0; i < 10; i++) scanf("%d", &val[i]);
  memset(dp, 0xef, sizeof(dp));
  dp[0][m] = 0;
  k++;
  for (int i = 1; i <= k; i++) solve(i), sort(i);
  printf("%d\n", dp[k][m]);
  return 0;
}
