#include<stdio.h>
#include<string.h>
#include<ctype.h>

typedef struct Node{
    int rowNum;
    int colNum;
}Matrix;

int main()
{
    int n;
    while(EOF != scanf("%d",&n))
    {
        Matrix matrix[n];
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&matrix[i].rowNum,&matrix[i].colNum);
        }
        char str[100];
        scanf("%s",str);
        Matrix stack[n];
        int index = -1;
        
        int alphaidnex = -1;
        int len = strlen(str);
        
        int countSum = 0;
        
        for(int i=0;i<len;i++)
        {
            if(isupper(str[i]))
            {
                ++alphaidnex;
                ++index;
                stack[index].rowNum = matrix[alphaidnex].rowNum;  // 入栈
                stack[index].colNum = matrix[alphaidnex].colNum;
            }else if(str[i] == ')')
            {
                Matrix temp;  
                temp.rowNum = stack[index-1].rowNum;
                temp.colNum = stack[index].colNum;
                countSum += stack[index-1].rowNum*stack[index].colNum*stack[index-1].colNum;
                index -= 2;   //出栈计算
                ++index; // 入栈计算结果
                stack[index].rowNum = temp.rowNum;
                stack[index].colNum = temp.colNum;
            }
        }
        printf("%d\n",countSum);
    }
    
    return 0;
}