#include<stdio.h> #include<string.h> char codes[][15]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen","eighteen", "nineteen", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty","ninety", "hundred","thousand", "million", "and"}; char s[1000],*p; int hao(char *p) { int i; for(i=0;i<=31;i++) if(strcmp(p,codes[i])==0) return i; } int main() { int t,x,sum,num; scanf("%d",&t); getchar(); while(t--) { gets(s); sum=0; num=0; int len=strlen(s); p=strtok(s," "); while(p) { x=hao(p); if(x<=20) num+=x; else if(x>=10&&x<=27) { num+=(x-18)*10; } else if(x==28) { num*=100; } else if(x==29) { num*=1000; sum+=num; num=0; } else if(x==30) { num*=1000000; sum+=num; num=0; } p=strtok(NULL," "); } printf("%d\n",sum+num); } return 0; }