Go: // Keitai Message
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2006&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var table = []string{
	"",
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz",
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	for i := 0; i < n; i++ {
		message := nextString(sc)
		currentButton, count := 0, 0
		for _, word := range message {
			// 確定の処理を書く
			if word == '0' {
				if currentButton == 0 {
					count = 0
					continue
				}
				mod := len(table[currentButton])
				tmp := table[currentButton][(count-1)%mod]
				currentButton, count = 0, 0
				fmt.Printf("%c", tmp)
			} else {
				count++
				currentButton = int(word) - 48 // '0'はASCIIで48
			}
		}
		fmt.Println()
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<bits/stdc++.h>

using namespace std;

int main(){
	string input;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>input;
		char first=input[0];
		int count=1;
		for(int j=1;j<input.size();j++){
			if(first==input[j])count++;
			if(input[j]=='0'){
				switch(first){
					case '1':
						switch(count%5){
							case 1:cout<<".";break;
							case 2:cout<<",";break;
							case 3:cout<<"!";break;
							case 4:cout<<"?";break;
							case 0:cout<<" ";break;
						}break;
					case '2':
						switch(count%3){
							case 1:cout<<"a";break;
							case 2:cout<<"b";break;
							case 0:cout<<"c";break;
						}break;
					case '3':
						switch(count%3){
							case 1:cout<<"d";break;
							case 2:cout<<"e";break;
							case 0:cout<<"f";break;
						}break;
					case '4':
						switch(count%3){
							case 1:cout<<"g";break;
							case 2:cout<<"h";break;
							case 0:cout<<"i";break;
						}break;
					case '5':
						switch(count%3){
							case 1:cout<<"j";break;
							case 2:cout<<"k";break;
							case 0:cout<<"l";break;
						}break;
					case '6':
						switch(count%3){
							case 1:cout<<"m";break;
							case 2:cout<<"n";break;
							case 0:cout<<"o";break;
						}break;
					case '7':
						switch(count%4){
							case 1:cout<<"p";break;
							case 2:cout<<"q";break;
							case 3:cout<<"r";break;
							case 0:cout<<"s";break;
						}break;
					case '8':
						switch(count%3){
							case 1:cout<<"t";break;
							case 2:cout<<"u";break;
							case 0:cout<<"v";break;
						}break;
					case '9':
						switch(count%4){
							case 1:cout<<"w";break;
							case 2:cout<<"x";break;
							case 3:cout<<"y";break;
							case 0:cout<<"z";break;
						}break;
				}
				first=input[j+1];
				count=0;
			}	
		}
		
			cout<<endl;	
	}
}

C++: #include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        vector<char> c[10];
        c[1]={'.', ',', '!', '?', ' '};
        char cur='a';
        For(i, 2, 10){
                rep(j, i==7 || i==9 ? 4 : 3){
                        c[i].push_back(cur);
                        ++cur;
                }
        }
        int q;
        scanf("%d", &q);
        while(q--){
                string s;
                cin>>s;
                int n=s.size();
                string t;
                int l=0;
                while(l<n){
                        if(s[l]=='0'){
                                ++l;
                                continue;
                        }
                        int r=l;
                        while(r<n && s[l]==s[r]) ++r;
                        t+=c[s[l]-'0'][(r-l-1)%(int)c[s[l]-'0'].size()];
                        l=r;
                }
                cout << t << "\n";
        }
}

C++: #include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    int n;
    string input;
    string output;
    string phone[10] =
    {
        " ",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"
    };
    int p;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> input;
        output = "";
        p = input.find('0');
        while(p != string::npos){
            switch(input[0]){
                case '1':
                output += phone[1][(p-1)%5];
                break;
                case '2':
                output += phone[2][(p-1)%3];
                break;
                case '3':
                output += phone[3][(p-1)%3];
                break;
                case '4':
                output += phone[4][(p-1)%3];
                break;
                case '5':
                output += phone[5][(p-1)%3];
                break;
                case '6':
                output += phone[6][(p-1)%3];
                break;
                case '7':
                output += phone[7][(p-1)%4];
                break;
                case '8':
                output += phone[8][(p-1)%3];
                break;
                case '9':
                output += phone[9][(p-1)%4];
                break;
            }
            input.erase(input.begin(), input.begin() + p + 1);
            p = input.find('0');
        }
        cout << output << endl;
    }
}

C++: #include <iostream>
#include <string>

#define rep(i,n) for(unsigned int i=0; i<n; i++)

void solve(void){

	int m;					//文字列の行数
	std::string sl;		//文字列格納用ストリング型変数

	char c[10][5] = {
		{},
		{'.',',','!','?',' '},
		{'a','b','c'},
		{'d','e','f'},
		{'g','h','i'},
		{'j','k','l'},
		{'m','n','o'},
		{'p','q','r','s'},
		{'t','u','v'},
		{'w','x','y','z'},
	};

	std::cin >> m;
	while(m--){

		int t = 0;

		std::cin >> sl;

		rep(i,sl.size()-1){
			if(sl[i] == sl[i+1]){
				t++;
			}else{
				if(sl[i]=='7' || sl[i]=='9'){
					t %= 4;
				}
				else if(sl[i]=='1'){
					t %= 5;
				}else{
					t %= 3;
				}
				if(sl[i] != '0'){
					std::cout << c[sl[i]-'0'][t];
				}
				t = 0;
			}
		}
		std::cout << std::endl;
	}
}

int main(void){

	solve();

	return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
  string s;
  cin>>s;
  char u=' ', b=0;
  char p[]={' ','.', 'a','d','g','j','m','p','t','w'};
  string t="";
  for(int i=0; i<s.size();i++) {
    int x=s[i]-'0';
    if (x==0) {
      if (b>0) {
      if (u=='.') {
        char f[]={'.',',','!','?', ' '};
        t+=string(1, f[b-1]);
      } else {
        t+=string(1, (char)(u+b-1));
      }
      b = 0;
      }
    } else {
      u=p[x];
      b++;
      if (x==7||x==9) {
        if (b==5) b=1;
      } else if (x==1) {
        if (b==6) b=1;
      } else if (b==4) b=1;
    }
  }
  cout<<t<<endl;
}
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  vector<string> num = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

  int n;
  cin >> n;
  string ans;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    
    ans = "";
    int j = 0;
    stack<int> st;
    for(int j = 0; j < s.length(); j++){
      if(s[j] == '0'){
        if(st.empty())continue;
        ans += num[st.top()][(st.size() - 1) % 3];

        while(!st.empty())st.pop();
      }else{
        st.push(s[j] - '0');
      }
    }
    cout << ans << endl;
  }
}