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>
#include<cstdio>
#include<cstring>

using namespace std;
int main(){
  char m[9][5]={{'.',',','!','?',' '},
		{'a','b','c','1','1'},
		{'d','e','f','1','1'},
		{'g','h','i','1','1'},
		{'j','k','l','1','1'},
		{'m','n','o','1','1'},
		{'p','q','r','s','1'},
		{'t','u','v','1','1'},
		{'w','x','y','z','1'}};
  int a,count=0,c[100],d;
  char b[1025];
  cin>>a;
  for(int i=0;i<a;i++){
    scanf("%s",b);
    c[i]=strlen(b);
    for(int j=0;j<c[i];j++){
      if(b[j]!='0')count++;
      else
	if(b[j-1]!=0){
	  d=(int)(b[j-1])-48;

	  if(d==1)
	    if(count%5!=0)
	      cout<<m[d-1][count%5-1];
	    else cout<<m[d-1][4];

	  else if(d==7 || d==9)
	    if(count%4!=0)
	      cout<<m[d-1][count%4-1];
	    else cout<<m[d-1][3];

	  else
	    if(count%3!=0)
	      cout<<m[d-1][count%3-1];
	    else cout<<m[d-1][2]; 
	  count=0;
	}
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string input;
		int count=1;
		
		cin>>input;
		char first=input[0];
		for(int j=1;j<input.size();j++){
			if(first==input[j])count++;
			if(input[j]=='0'){
				if(input[j+1]=='0')continue;
				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 <iostream>

using namespace std;

int main()
{
    int num;
    const string kei[] = {".,!? ",
                          "abc",
                          "def",
                          "ghi",
                          "jkl",
                          "mno",
                          "pqrs",
                          "tuv",
                          "wxyz" };

    cin >> num;
    for (int i = 0; i < num; i++) {
        string inp;
        char bf = '0';
        int cnt = 0;

        cin >> inp;
        for (int i = 0; i < inp.size(); i++) {
            if (inp[i] != '0') {
                bf = inp[i];
                cnt++;
            }
            else if (inp[i] == '0' && bf != '0') {
                int ind = bf - '0' - 1;
                cnt--;
                cnt = cnt % kei[ind].size();

                cout << kei[ind][cnt];
                cnt = 0;
                bf = '0';
            }
        }
        cout << endl;
    }

    return 0;
}

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

char moji[9][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'}
};

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for(int j = 0; j < s.size(); j++) {
      char c = s[j];
      if(c == '0') continue;
      for(int k = 0; j+k < s.size(); k++) {
	if(s[j+k+1] == '0') {
	  int num = c-'0'-1;
	  if(num == 0) printf("%c", moji[num][k%5]);
	  else if(num == 6 || num == 8) printf("%c", moji[num][k%4]);
	  else printf("%c", moji[num][k%3]);
	  j += k;
	  break;
	}
      }
    }
    cout << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		string key[]={".,!?, ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
		string input;
		cin>>input;
		stringstream b(input);
		int num=0,count=0;
		while(1){
			char c;
			if(!(b>>c))break;
			int input=c-'0';
			if(input!=0){
				count++;
				num=input;
			}
			else {
				if(count!=0)
					cout<<key[num-1][(count-1)%key[num-1].size()];
				num=0;count=0;
			}
		}
		cout<<endl;
	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;



int main(){
    int n;
    cin>>n;
    string s;
    vector<string> a(10);
    a[1] = ".,!? ";
    a[2] = "abc";
    a[3] = "def";
    a[4] = "ghi";
    a[5] = "jkl";
    a[6] = "mno";
    a[7] = "pqrs";
    a[8] = "tuv";
    a[9] = "wxyz";

    while(n--){
        cin>>s;
        int n=s.size();
        string ans;
        int cnt=0;
        rep(i,n){
            if(cnt==0 and s[i]=='0') continue;
            if(s[i]=='0'){
                int idx = s[i-1]-'0';
                cnt--;
                cnt %= a[idx].size();
                ans.push_back(a[idx][cnt]);
                cnt = 0;
            }else{
                cnt++;
            }
        }
        if(ans=="") continue;
        cout << ans << endl;
    }
}