import java.util.Scanner;

public class Main {
    private static int res = 0;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] a = new int[n][2];
        for (int i = 0; i < n; i++) {
            a[i][0] = in.nextInt();
            a[i][1] = in.nextInt();
        }
        in.nextLine();
        String line = in.nextLine();
        getResult(line.substring(1,line.length()-1),a);
        System.out.print(res);
    }
    //返回算式的结果矩阵
    public static int[] getResult(String line, int[][] all) {
        // System.out.printf("line:%s,",line);
        int[] a = null;
        int[] b = null;
        for (int i = 0; i < line.length(); i++) {
            char ch = line.charAt(i);
            if (ch == '(') {
                int count = 1;
                int left = i;
                while (count != 0) {
                    i++;
                    if (line.charAt(i) == '(') {
                        count++;
                    } else if (line.charAt(i) == ')') {
                        count--;
                    }
                }
                int[] temp = getResult(line.substring(left + 1, i), all);
                if (a == null) {
                    a = temp;
                } else {
                    b = temp;
                }
            } else {
                int index = ch - 'A';
                int[] temp = all[index];
                if (a == null) {
                    a = temp;
                } else {
                    b = temp;
                }
            }
        }
        // System.out.printf("a:%d %d,",a[0],a[1]);
        // System.out.printf("b:%d %d,",b[0],b[1]);
        return calc(a, b);
    }

    //矩阵相乘,记录次数,并返回相乘结果
    public static int[] calc(int[] a, int[] b) {
        res += a[0] * a[1] * b[1];
        return new int[] {a[0], b[1]};
    }
}