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 <iostream>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)

using namespace std;

int main()
{
  char keitai[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', '*'},
  };
  string s;
  int x , c;
  char p;
  int n;
  cin >> n;
  cin.ignore();
  REP(k, n){
    getline(cin, s);
    x = c = 0;
    p = '*';
    REP(i, s.size()){
      int j;
      j = s[i] - '0';
      if(j){
        if(x == j){
          if(keitai[j][c + 1] == '*'){
            c = 0;
            p = keitai[j][c];
          }else{
            c++;
            p = keitai[j][c];
          }
        }else{
          c = 0;
          p = keitai[j][c];
        }
      }else{
        if(p != '*')
          cout << p;
        p = '*';
      }
      x = j;
    }
    cout << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s[]={"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  int n; cin>>n;
  while(n--){
    string t,ans;
    cin >> t;
    int cnt=-1,num=0;
    for(int i=0;i<t.size();++i){
      if(t[i]=='0'){
        if(cnt!=-1){
          ans+=s[num][cnt%s[num].size()];
          cnt=-1;
        }
      }else{
        num=t[i]-'0';
        cnt++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;

signed main(){
  vector<string> str={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  int n;
  cin>>n;
  while(n--){
    string s;
    cin>>s;
    vector<pair<int,int>> p;
    REP(i,s.size()){
      int c=s[i]-'0';
      if(c==0)continue;
      int tmp=-1;
      while(s[i]!='0'){
        tmp++;
        i++;
      }
      p.PB(MP(c-1,tmp));
    }
    REP(i,p.size()){
      int f=p[i].FR;int sc=p[i].SC;
      if(f==0)cout<<str[0][sc%5];
      else if(f==6||f==8)cout<<str[f][sc%4];
      else cout<<str[f][sc%3];
    }
    cout<<endl;
   }
  return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<char> button1={'.',',','!','?',' '};
    int n; cin >> n;
    for (int i=0;i<n;++i){
        string s,ans=""; cin >> s;
        int cnt=-1;
        for (int j=0;j<s.size();++j){
            if (s[j]!='0'){++cnt; continue;}
            if (j==0||s[j-1]=='0') continue;
            int x=s[j-1]-'0';
            if (x==1) ans+=button1[cnt%5];
            else if (x==7) ans+='p'+cnt%4;
            else if (x==8) ans+='t'+cnt%3;
            else if (x==9) ans+='w'+cnt%4;
            else ans+='a'+((x-2)*3+cnt%3);
            cnt=-1;
        }
        cout << ans << endl;
    }
}

C++: #include<stdio.h>
#include<string.h>
main(){
    int N;
    char S[77];
    scanf("%d",&N);
    char str[][6] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    for(int i = 0;i < N;i++){
        scanf("%s",S);
        int num = 0;//?????¨??\??????????????????
        int count = 0;
        for(int j = 0;j < strlen(S);j++){
            if(S[j] != '0'){num = S[j] - '0';}
            if(S[j] == '0' && num == 0){continue;}
            if(S[j] == S[j+1]){
                count++;
                continue;
            }
            printf("%c",str[num-1][count%(strlen(str[num-1]))]);
            count = 0;
            num = 0;
        }
        printf("\n");
    }
}

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

using namespace std;

vector<string> V;

int main(){
    V.push_back("");
    V.push_back(".,!? ");
    V.push_back("abc");
    V.push_back("def");
    V.push_back("ghi");
    V.push_back("jkl");
    V.push_back("mno");
    V.push_back("pqrs");
    V.push_back("tuv");
    V.push_back("wxyz");

    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string out = "";
        string inp = "";
        cin >> inp;
        char now;
        int kai;
        now = '0';kai = 0;
        for(int j=0;j<inp.length();j++){
            if(inp[j] == '0'){
                if(kai != 0){
                    kai--;
                    out += V[now-'0'][kai%(V[now-'0'].length())];
                }
                now = inp[j];
                kai = 0;
                continue;
            }
            now = inp[j];
            kai++;
        }
        cout << out << endl;
    }
}

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;
  }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

#define all(i) i.begin(), i.end()
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
	int num = 0; cin >> num;
	string dat[12] = { "", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	rep(i, num)
	{
		string str; cin >> str;
		vector<int> hit(10, 0);
		rep(j, (int)str.size())
		{
			hit[str[j] - '0'] += 1;
			if (j == 0 || str[j - 1] == '0') {}
			else if (str[j] == '0')
			{
				int tmp = str[j - 1] - '0', n = hit[tmp];
				while (1)
				{
					if (n <= (int)dat[tmp].size()) { break; }
					n -= (int)dat[tmp].size();
				}
				/*n = hit[tmp] % (int)dat[tmp].size();
				if (n == 0){ n = hit[tmp] + 1; }
				if (n >= 3 && (int)dat[tmp].size() == 3) { n -= 1; }*/
				printf("%c", dat[tmp][n - 1]);
				rep(i, 10){ hit[i] = 0; }
			}
		}
		printf("\n");
	}
	return 0;
}