#include #include #include #include using namespace std; int c, d, n, sol; string s; vector S; string word; map A = { {"Zero", 0}, {"One", 1}, {"Two", 2}, {"Three", 3}, {"Four", 4}, {"Five", 5}, {"Six", 6}, {"Seven", 7}, {"Eight", 8}, {"Nine", 9}, {"Ten", 10}, {"Eleven", 11}, {"Twelve", 12}, {"Thirteen", 13}, {"Fourteen", 14}, {"Fifteen", 15}, {"Sixteen", 16}, {"Seventeen", 17}, {"Eighteen", 18}, {"Nineteen", 19}, {"Twenty", 20}, {"Thirty", 30}, {"Forty", 40}, {"Fifty", 50}, {"Sixty", 60}, {"Seventy", 70}, {"Eighty", 80}, {"Ninety", 90}}; map B = { {"Hundred", 100}, {"Thousand", 1000}, {"Million", 1000000}}; int stonum(vector words) { c = 0; d = 0; for (string s : words) { if (s == "END") { break; } else if (A.count(s)) { c += A[s]; } else if (s == "Hundred") { c *= B[s]; } else if (s == "Thousand" || s == "Million") { c *= B[s]; d += c; c = 0; } } return d + c; } int main() { freopen("gptS.in", "r", stdin); freopen("gptS.out", "w", stdout); cin >> n; getline(cin, s); for (int i = 1; i <= n; i++) { getline(cin, s); stringstream ss(s); while (ss >> word) { S.push_back(word); } sol = stonum(S); cout << sol << endl; S.clear(); } return 0; }