Go: package main

import (
	"bytes"
	"fmt"
)

//Ktai has a keyboard and a state.
type Ktai struct {
	keyboard KeyBoard
	textBuf  *bytes.Buffer
}

// KeyBoard is type of a map.
type KeyBoard map[rune]string

// KEYBOARD that Ktai has
var KEYBOARD = KeyBoard{
	'0': "",
	'1': ".,!? ",
	'2': "abc",
	'3': "def",
	'4': "ghi",
	'5': "jkl",
	'6': "mno",
	'7': "pqrs",
	'8': "tuv",
	'9': "wxyz",
}

func main() {
	var N int
	fmt.Scanf("%d", &N)
	ktai := &Ktai{
		KEYBOARD, &bytes.Buffer{},
	}
	for i := 0; i < N; i++ {
		var numstr string
		fmt.Scanf("%s", &numstr)
		ktai.feed(numstr)
		ktai.print()
	}
}

func (ktai *Ktai) feed(str string) {
	var char *byte
	for _, v := range str {
		if v == '0' {
			if char != nil {
				ktai.textBuf.WriteByte(*char)
				char = nil
			}
			continue
		} else {
			runestring := ktai.keyboard[v]
			idx := ktai.indexOf(char, runestring)
			next := (idx + 1) % len(runestring)
			c := runestring[next]
			char = &c
		}
	}
}

func (ktai *Ktai) indexOf(ch *byte, str string) int {
	if ch == nil {
		return -1
	}
	r := rune(*ch)
	idx := -1
	for i, v := range str {
		if r == v {
			idx = i
			break
		}
	}
	return idx
}

func (ktai *Ktai) print() {
	fmt.Println(ktai.textBuf.String())
	ktai.textBuf.Reset()
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	string b[10];
	b[1] = ".,!? ";
	b[2] = "abc";
	b[3] = "def";
	b[4] = "ghi";
	b[5] = "jkl";
	b[6] = "mno";
	b[7] = "pqrs";
	b[8] = "tuv";
	b[9] = "wxyz";
/*
	b[1][] = { '.', ',', '!', '?', ' ' };
	b[2][] = { 'a', 'b', 'c' };
	b[3][] = { 'd', 'e', 'f' };
	b[4][] = { 'g', 'h', 'i' };
	b[5][] = { 'j', 'k', 'l' };
	b[6][] = { 'm', 'n', 'o' };
	b[7][] = { 'p', 'q', 'r', 's' };
	b[8][] = { 't', 'u', 'v' };
	b[9][] = { 'w', 'x', 'y', 'z' };
*/
//	cut here before submit 
//	freopen ("testcase.KM", "r", stdin );
	int n;
	scanf ("%d", &n );
	while (n-- ){
		string mesg = "";
		cin >> mesg;
		int m = mesg.length();
		int c = -1, cnt = -1;
		string ans = "";
		rep (i, m ){
			if (mesg[i] != '0' ){
				c = (char)(mesg[i] - '0');
				cnt++;
			}else{
				if (c != -1 ){
//					if (cnt == 1 ) cnt--;
					ans += b[c][(cnt) % b[c].length() ];
				} // end if
				c = -1;
				cnt = -1;
			} // end if
		} // end rep
		cout << ans << endl;
	} // end loop
		
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main() {
	int a[1030];
	int k;
	stringstream sout;
	string b;
	int kari;
	while (cin >> b) {
		kari = 0;
		int rireki[10] = {0};
		k = b.size();
		for (int i = 0; i < k; i++) {
			sout.str("");
			sout.clear();
			sout << b[i];
			sout >> a[i];
		}
		for (int i = 0; i < k-1; i++) {
			if(a[i] != a[i+1] && a[i+1] == 0 && a[i] != 0) {
				kari = 1;
				if (a[i] == 1) {
					if(rireki[1] % 5 == 0) {
						printf(".");
					} else if (rireki[1] % 5 == 1) {
						printf(",");
					} else if (rireki[1] % 5 == 2) {
						printf("!");
					} else if (rireki[1] % 5 == 3) {
						printf("?");
					} else {
						printf(" ");
					}
					rireki[1] = 0;
				} else if (a[i] == 2) {
					//printf(" %d \n", rireki[2]);
					if(rireki[2] % 3 == 0) {
						printf("a");
					} else if (rireki[2] % 3 == 1) {
						printf("b");
					} else {
						printf("c");
					}
					rireki[2] = 0;
				} else if (a[i] == 3) {
					if (rireki[3] % 3 == 0) {
						printf("d");
					} else if (rireki[3] % 3 == 1) {
						printf("e");
					} else {
						printf("f");
					}
					rireki[3] = 0;
				} else if (a[i] == 4) {
					if (rireki[4] % 3 == 0) {
						printf("g");
					} else if (rireki[4] % 3 == 1) {
						printf("h");
					} else {
						printf("i");
					}
					rireki[4] = 0;
				} else if (a[i] == 5) {
					if (rireki[5] % 3 == 0) {
						printf("j");
					} else if (rireki[5] % 3 == 1) {
						printf("k");
					} else {
						printf("l");
					} 
					rireki[5] = 0;
				} else if (a[i] == 6) {
					if (rireki[6] % 3 == 0) {
						printf("m");
					} else if (rireki[6] % 3 == 1) {
						printf("n");
					} else {
						printf("o");
					}
					rireki[6] = 0;
				} else if (a[i] == 7) {
					if (rireki[7] % 4 == 0) {
						printf("p");
					} else if (rireki[7] % 4 == 1) {
						printf("q");
					} else if (rireki[7] % 4 == 2) {
						printf("r");
					} else {
						printf("s");
					}
					rireki[7] = 0;
				} else if (a[i] == 8) {
					if (rireki[8] % 3 == 0) {
						printf("t");
					} else if(rireki[8] % 3 == 1) {
						printf("u");
					} else {
						printf("v");
					}
					rireki[8] = 0;
				} else {
					if (rireki[9] % 4 == 0) {
						printf("w");
					} else if (rireki[9] % 4 == 1) {
						printf("x");
					} else if (rireki[9] % 4 == 2) {
						printf("y");
					} else {
						printf("z");
					}
					rireki[9] = 0;
				}
			} else {
				if (a[i] == 0 || (a[i] != a[i+1])) {
					rireki[a[i]] = 0;
					continue;
				}
				rireki[a[i]]++;
			}
		}
		if (kari == 1) {
			printf("\n");
			}
	}
	return 0;
}

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

int main(){
	string chg[] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		int now = -1,num = -1;
		for(int j = 0;j < s.length();j++){
			if(s[j] == '0'){
				if(now == -1 && num == -1) continue;
				cout << chg[now][num % chg[now].length()];
				num = -1;
				now = -1;
			}else{
				now = s[j] - '1';
				num++;
			}
		}
		cout << endl;
	}
	return 0;
}

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdlib>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=true;

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

  cin>>n;
  for(int i=0;i<n;i++){
    //cout<<"DEBUG"<<endl;
    string ss;
    cin>>ss;
    int cnt=0;
    for(int j=0;j<ss.size();j++){
      if(ss[j]=='0'&&cnt!=0){
	int x=int(ss[j-1])-48;
	//cout<<x<<endl;
	cout<<s[x][(cnt-1)%int(s[x].size())];
	cnt=0;
      }else if(ss[j]=='0'&&cnt==0){
	cnt=0;
      }else{
	cnt++;
      }
    }
    cout<<endl;
  }
  
  return 0;
}