#include<stdio.h>
int change(int val,int base)
{
int result = 0,weight = 1;
while(val){
result += (val%10)*weight;
val/=10;
weight*=base;
}
return result;
}
int main()
{
int n;
int val,base;
while(~scanf("%d",&n))
{
int sum = 0;
for(int i = 0;i<n;i++)
{
scanf("%d(%d)",&val,&base);
if(base==10) sum+=val;
else sum+=change(val,base);
}
printf("%d
",sum);
}
return 0;
}