#include #define ll long long using namespace std; int N; int str_to_int(string s) { if(s == "One") return 1; if(s == "Two") return 2; if(s == "Three") return 3; if(s == "Four") return 4; if(s == "Five") return 5; if(s == "Six") return 6; if(s == "Seven") return 7; if(s == "Eight") return 8; if(s == "Nine") return 9; if(s == "Ten") return 10; if(s == "Eleven") return 11; if(s == "Twelve") return 12; if(s == "Thirteen") return 13; if(s == "Fourteen") return 14; if(s == "Fifteen") return 15; if(s == "Sixteen") return 16; if(s == "Seventeen") return 17; if(s == "Eighteen") return 18; if(s == "Nineteen") return 19; if(s == "Twenty") return 20; if(s == "Thirty") return 30; if(s == "Forty") return 40; if(s == "Fifty") return 50; if(s == "Sixty") return 60; if(s == "Seventy") return 70; if(s == "Eighty") return 80; if(s == "Ninety") return 90; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); freopen("gptS.in", "r", stdin); freopen("gptS.out", "w", stdout); cin >> N; while(N--) { vector S; int sol = 0; while(true) { string s; cin >> s; if(s == "END") { reverse(S.begin(), S.end()); int mult = 1; for(string x : S) { if(x != "Hundred" and x != "Thousand" and x != "Million" and x != "Billion") sol += mult * str_to_int(x); if(x == "Hundred") mult *= 100; if(x == "Thousand") mult = 1000; if(x == "Million") mult = 1e6; if(x == "Billion") mult = 1e9; } break; } S.push_back(s); } cout << sol << '\n'; } return 0; }