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

package main

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

// 標準入力を取得するScannerのインスタンスを作成
var scanner = bufio.NewScanner(os.Stdin)

// 標準入力で各行を読み込みstringとして返す
func readLine() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func main() {
	// 1: . , ! ? (スペース)
	// 2: a b c
	// 3: d e f
	// 4: g h i
	// 5: j k l
	// 6: m n o
	// 7: p q r s
	// 8: t u v
	// 9: w x y z
	// 0: 確定ボタン

	// 改行から空白区切りに変更
	scanner.Split(bufio.ScanWords)
	line, _ := strconv.Atoi(readLine()) // 5行標準入力が続く

	table := []string{
		"",      // 0 index調整ためダミーデータ
		".,!? ", // 1
		"abc",   // 2
		"def",   // 3
		"ghi",   // 4
		"jkl",   // 5
		"mno",   // 6
		"pqrs",  // 7
		"tuv",   // 8
		"wxyz"}  // 9

	// 5行分の標準入力を格納するsliceを作成する
	messages := make([]string, 0, line)

	// sliceに標準入力の内容を格納する
	for i := 0; i < line; i++ {
		messages = append(messages, readLine()) // messages=[20 220 222220 44033055505550666011011111090666077705550301110 000555555550000330000444000080000200004440000]
	}

	// 各行毎に解析する
	for _, message := range messages { // message=000555555550000330000444000080000200004440000
		// 0で分割する
		messageSlice := strings.Split(message, "0") // messageSlice=[   55555555    33    444    8    2    444    ]
		for _, word := range messageSlice {
			if word == "" {
				// NOP.
				// 0をセパレーターにしているので空文字がsliceに格納されてい箇所がある
				// 何もしない
			} else { // word=55555555
				// 一文字取り出しコード値をASCII文字に変換する
				ascii := string((word[0])) // word[0]=5

				// ASCII文字からintへ変換する(tableのindexになる)
				number, _ := strconv.Atoi(ascii)

				// 入力回数をカウントする
				count := len(word) // 5

				// 同じ数字を続けて入力すると変化する文字はループすることを考慮する
				for count > len(table[number]) { // 5 > 3
					count -= len(table[number]) // 2
				}

				// キー配列
				keys := table[number]                   //jkl
				fmt.Printf("%s", string(keys[count-1])) //k
			}
		}
		fmt.Println() // 改行
	}
}

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

C++: // 2006_KeitaiMessage.cpp
//
#include <bits/stdc++.h>
using namespace std;
int n;
string m;
char d[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'},
};
int len[10] = {-1, 5, 3, 3, 3, 3, 3, 4, 3, 4};

vector<string> split(string &str, char sep) {
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while(getline(ss, buffer, sep)) {
    if(buffer != "") v.push_back(buffer);
  }
  return v;
}

void solve() {
  vector<string> v1 = split(m, '0');
  for_each(v1.begin(), v1.end(), [](string& x) {
      int a = x[0] - '0';
      int b = x.length();
      int c = (b <= len[a] ? b - 1 : b % len[a] - 1);
      cout << d[a][c];
    });
  cout << endl;
}

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> m;
    solve();
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
using namespace std;

void p(int nu, int key){
//cout<<"dckjw"<<nu<<" "<<key<<endl;
string s[10]={"",".,!?","cab","fde","igh","ljk","omn","spqr","vtu","zwxy"};
if(key==1){
nu=nu%5;
if(nu==0) cout<<" ";
else cout<<s[1][nu-1];
}
if(key==2){
nu=nu%3;
//cout<<s[2];
cout<<s[2][nu];
}
if(key==3){
nu=nu%3;
cout<<s[3][nu];
}
if(key==4){
nu=nu%3;
cout<<s[4][nu];
}
if(key==5){
nu=nu%3;
cout<<s[5][nu];
}
if(key==6){
nu=nu%3;
cout<<s[6][nu];
}
if(key==7){
nu=nu%4;
cout<<s[7][nu];
}
if(key==8){
nu=nu%3;
cout<<s[8][nu];
}
if(key==9){
nu=nu%3;
cout<<s[9][nu];
}


}
int main(){
string s;
int n,l;
cin>>n;
for(int www=0;www<n;www++){
cin>>s;
l=s.length();
int nu=1,key;
key=s[0]-'0';


for(int j=0;j<l-1;j++){
if(s[j]!=s[j+1]){
p(nu,key);
nu=1;
key=s[j+1]-'0';
}
else{
nu++;
}

}
p(nu,key);
cout<<endl;
}
return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

char c[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'},
};

string s;

int main(){
	cin.sync_with_stdio(false);
	int cases;
	cin>>cases;
	while(cases--){
		cin>>s;
		string res;
		int i=0;
		while(1){
			while(i<s.length()&&s[i]=='0')i++;
			if(i==s.length())break;
			int cnt=0;
			while(i<s.length()&&s[i]!='0')cnt++,i++;
			int k=s[i-1]-'1';
			int r;
			if(k==0)r=5;
			else if(k==6||k==8)r=4;
			else r=3;
			res+=c[k][(cnt-1)%r];
		}
		cout<<res<<endl;
	}
	return 0;
}

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(){
			char c;
			if(b>>c)break;
			int input=atoi(c);
			if(input!=0){
				count++;
				num=input;
			}
			else {
				if(count!=0)
					count<<key[num-1][count%key[num-1].size()];
				num=0;count=0;
			}
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

string keyd[] = {"",".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		string input; cin >> input;
		int pos = -1, key = 0;
		string::iterator itr = input.begin();
		while(itr != input.end()){
			if( *itr == '0'){
				if(key == 0){
					itr++;
					continue;
				}
				pos = pos % keyd[key].size();
				cout << keyd[key][pos];
				pos = -1;
				key = 0;
			}
			else{
				if(pos == -1)key = *itr - '0';
				pos++;
			}
			itr++;
		}
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;
typedef pair<int, int> P;

/** Problem2006 : Keitai Message **/
int main()
{
	string list[10] = {"#", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	int l[10] = {0, 5, 3, 3, 3, 3, 3, 4, 3, 4};
	int n;
	cin >> n;
	rep(k, n) {
		string in, ans;
		cin >> in;
		int tmp=-1; char c='#';
		rep(i, in.length()) {
			if (in[i]!='0') {
				tmp++; tmp%=l[in[i]-'0'];
				c = list[in[i]-'0'][tmp];
			} else {
				if (c != '#')
					ans+=c;
				tmp=-1;
				c='#';
			}
		}
		cout << ans << endl;
	}
}