Boris really likes numbers and even owns a small shop selling interesting numbers. He has n decimal numbers Bi. Cost of the number in his shop is equal to the sum of costs of its digits. You are given the values cd, where cd is the cost of the digit d. Of course, Boris is interested in that numbers he owns have the maximum cost possible.

Recently Boris got hold of the magical artifact A, which can allow him to increase the cost of his collection. Artifact is a string, consisting of digits and '?' symbols. To use the artifact, Boris must replace all '?' with digits to get a decimal number without leading zeros (it is also not allowed to get number 0). After that, the resulting number is added to all numbers Bi in Boris' collection. He uses the artifact exactly once.

What is the maximum cost of the collection Boris can achieve after using the artifact?

Input

First line contains artifact A, consisting of digits '0'–'9' and '?' symbols (1 ≤ |A| ≤ 1000). Next line contains n — the amount of numbers in Boris' collection (1 ≤ n ≤ 1000). Next n lines contain integers Bi (1 ≤ Bi < 101000). A doesn't start with '0'.

Last line contains ten integers — costs of digits c0, c1, ..., c9 (0 ≤ ci ≤ 1000).

Output

Output one integer — the maximum possible cost of the collection after using the artifact.

Examples

Input

42
3
89
1
958
0 0 1 1 2 2 3 3 4 4


Output

4


Input

?5?
4
2203
5229
276
6243
2 1 6 1 1 2 5 2 2 3


Output

62

Note

In the second sample input, the optimal way is to compose the number 453. After adding this number, Boris will have numbers 2656, 5682, 729 and 6696. The total cost of all digits in them is equal to 18 + 15 + 11 + 18 = 62. 
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.stream.Stream;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, FastReader in, FastWriter out) {
            String a = in.nextLine();
            a = Strings.reverse(a);
            int m = a.length();
            int n = in.nextInt();
            String b[] = new String[n];
            for (int i = 0; i < n; i++) {
                b[i] = Strings.reverse(in.nextString());
                m = Math.max(m, b[i].length());
            }
            m += 1;
            int cost[] = new int[10];
            for (int i = 0; i < 10; i++) {
                cost[i] = in.nextInt();
            }
            int order[] = new int[n];
            long dp[] = new long[n + 1];
            int placed[] = new int[n];
            int nextOrder[] = new int[n];
            long nextDP[] = new long[n + 1];
            Arrays.fill(dp, -1);
            dp[n] = 0;
            for (int i = 0; i < m; ++i) {
                Pair<Integer, Integer>[] toSort = new Pair[n];
                for (int number = 0; number < n; number++) {
                    toSort[number] = new Pair<>(
                            i >= b[number].length() ? 0 : get(b[number], i),
                            order[number]
                    );
                }
                int nextPlaced[] = ArrayTools.sortIndices(toSort);
                for (int j = 0; j < n; j++) {
                    nextOrder[nextPlaced[j]] = j;
                }
                Arrays.fill(nextDP, -1);
                for (int digit = 0; digit < 10; digit++) {
                    if (i == a.length() - 1 && digit == 0) continue;
                    if (i >= a.length() && digit != 0) continue;
                    if (i < a.length() && a.charAt(i) != '?' && get(a, i) != digit) continue;
                    long total = 0;
                    for (int j = 0; j < n; j++) {
                        if (i < b[j].length() || i < a.length()) {
                            total += cost[(get(b[j], i) + digit) % 10];
                        }
                    }
                    int nextCurry = n;
                    for (int prevCurry = n; prevCurry >= 0; --prevCurry) {
                        while (nextCurry > 0 &&
                                ((toSort[nextPlaced[nextCurry - 1]].x + digit == 9 && toSort[nextPlaced[nextCurry - 1]].y == prevCurry) || toSort[nextPlaced[nextCurry - 1]].x + digit >= 10)) {
                            --nextCurry;
                        }
                        if (prevCurry < n) {
                            int j = placed[prevCurry];
                            if (i < b[j].length() || i < a.length()) {
                                total -= cost[(get(b[j], i) + digit) % 10];
                            }
                            total += cost[(1 + get(b[j], i) + digit) % 10];
                        }
                        if (dp[prevCurry] != -1 && nextDP[nextCurry] < dp[prevCurry] + total) {
                            nextDP[nextCurry] = dp[prevCurry] + total;
                        }
                    }
                }
                order = nextOrder.clone();
                dp = nextDP.clone();
                placed = nextPlaced.clone();
            }

            long ans = 0;
            for (long x : dp) {
                ans = Math.max(ans, x);
            }
            out.println(ans);
        }

        private int get(String s, int i) {
            if (i < s.length()) return s.charAt(i) - '0';
            return 0;
        }

    }

    static class Pair<X, Y> implements Comparable<Pair<X, Y>> {
        public X x;
        public Y y;

        public Pair(X x, Y y) {
            this.x = x;
            this.y = y;
        }


        public int hashCode() {
            int res = x == null ? 0 : x.hashCode();
            return res * 31 + (y == null ? 0 : y.hashCode());
        }


        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null) return false;
            if (getClass() != o.getClass()) return false;
            Pair p = (Pair) o;
            if ((x == null && p.x != null) || !x.equals(p.x)) return false;
            if ((y == null && p.y != null) || !y.equals(p.y)) return false;
            return true;
        }


        public String toString() {
            return String.format("(" + x + ", " + y + ")");
        }


        @SuppressWarnings({"unchecked"})
        public int compareTo(Pair<X, Y> o) {
            int res = ((Comparable<X>) x).compareTo(o.x);
            if (res != 0) return res;
            return ((Comparable<Y>) y).compareTo(o.y);
        }

    }

    static class Strings {
        public static String reverse(String s) {
            return new StringBuffer(s).reverse().toString();
        }

    }

    static class FastWriter {
        PrintWriter writer;

        public FastWriter(OutputStream stream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
        }

        public FastWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println(long l) {
            writer.println(l);
        }

        public void close() {
            writer.close();
        }

    }

    static class ArrayTools {
        public static int[] enumerate(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = i;
            return a;
        }

        @SuppressWarnings("unchecked")
        public static <T> int[] sortIndices(T a[]) {
            return Arrays.stream(enumerate(a.length)).boxed().sorted((x, y) -> ((Comparable) a[x]).compareTo(a[y])).mapToInt(i -> i).toArray();
        }

    }

    static class FastReader {
        final int EOF = -1;
        InputStream stream;
        byte[] buf = new byte[8192];
        int bufSize;
        int bufPos;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (bufPos >= bufSize) {
                bufPos = 0;
                try {
                    bufSize = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (bufSize <= 0) {
                    return EOF;
                }
            }
            return buf[bufPos++];
        }

        public int nextInt() {
            int c = read();
            while (isSpace(c)) {
                c = read();
            }
            int sign = 1;
            if (c == '-') {
                sign = EOF;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10 + c - '0';
                c = read();
            } while (!isSpace(c));
            return res * sign;
        }

        public String nextString() {
            int c = read();
            while (isSpace(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpace(c));
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            int c = read();
            while (c != '\n' && c != EOF) {
                if (c != '\r') {
                    res.appendCodePoint(c);
                }
                c = read();
            }
            return res.toString();
        }

        public boolean isSpace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == EOF;
        }

    }
}

