#include #include #include #include #include using namespace std; char *table[] = { NULL, // 確定 ".,!? ", "abc", "def" , "ghi" , "jkl", "mno" , "pqrs" , "tuv", "wxyz", }; // とてもstrictなルールを書いてみた string decode(const string& s) { string result; int cursor = 0; while(cursor < s.size()) { char c = s[cursor]; if(! isdigit(c)) { // 数字でない cerr << "Non-digit character at idx=" << cursor << endl; assert(false); } if(c == '0') { // 文字が入力されていない状態で確定キー /*cerr << "Empty input at idx=" << cursor << endl; assert(false);*/ // just ignoring 0 cursor++; continue; } int next = s.find_first_not_of(c, cursor + 1); if(next == string::npos) next = s.size(); if(next >= s.size() || s[next] != '0') { // 0 で確定されていない cerr << "Character sequence does not terminate with 0 at idx=" << next << endl; assert(false); } c -= '0'; result += table[c][(next - cursor - 1) % strlen(table[c])]; cursor = next + 1; } return result; } int main() { int ncase; string s; cin >> ncase; getline(cin, s); while(ncase--) { getline(cin, s); cout << decode(s) << endl; } return 0; }