#include using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") #define endl "\n" template inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } #ifndef LOCAL #define cerr if(false) cerr #endif #define out(x) #x << " = " << x << " " template ostream& operator<<(ostream &os, const pair &p) { return os << "(" << p.first << ", " << p.second << ")"; } template< typename T, typename B = decay()))>, typename enable_if::value>::type* = nullptr > ostream& operator<<(ostream &os, const T &c) { bool f = false; os << "("; for (const auto &x : c) { if (f) os << ", "; f = true; os << x; } return os << ")"; } typedef long long ll; const ll mod = 1000000007; const int MAX_N = 1000000 + 10; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// std::unordered_map WORD_VAL = { {"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} }; void solve() { ll total = 0, current = 0; std::string w; while (cin >> w && w != "END") { for (auto &c : w) c = tolower(c); if (w == "hundred") { current *= 100; } else if (w == "thousand") { total += current * 1000; current = 0; } else if (w == "million") { total += current * 1000000; current = 0; } else { current += WORD_VAL[w]; } } total += current; std::cout << total << endl; } signed main() { #ifndef LOCAL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); std::freopen("gptS.in", "r", stdin); std::freopen("gptS.out", "w", stdout); #endif int t; std::cin >> t; while(t--){ solve(); } return 0; }