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<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n;
	cin >> n;
	int i,j;
	string s;
	char trans[10][5];
	for (int i = 0; i < 4; i++)trans[0][i] = '0';
	trans[1][0] = '.'; trans[1][1] = ','; trans[1][2] = '!'; trans[1][3] = '?';
	for (i = 2; i < 10; i++) {
		for (j = 0; j < 4; j++) {
			if (i != 9 &&i!=7&& j == 3)trans[i][j] = '0';
			else if(i<8) trans[i][j] = 'a' + (i - 2) * 3 + j;
			else trans[i][j] = 't' + (i - 8) * 3 + j;
		}
	}
	char trans1[5] = { '.',',','!','?',' ' };
	for (i = 0; i < n; i++) {
		cin >> s;
		int len = s.length();
		int check = 0;
		int memo = 0;
		for (j = 0; j < len; j++) {
			if (check > 0 && s[j] == '0') {
				if (memo == 1) cout << trans1[(check - 1) % 5];
				else if (memo == 7 || memo == 9) {
					cout << trans[memo][(check-1) % 4];
				}
				else cout << trans[memo][(check-1) % 3];
				check = 0;
			}
			else if (s[j] != '0') {
				memo = s[j] - '0'; check++;
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
vector<char>s[10];
main()
{
	string t;
	t=".,!? ";for(int i=0;i<t.size();i++)s[1].push_back(t[i]);
	t="abc";for(int i=0;i<t.size();i++)s[2].push_back(t[i]);
	t="def";for(int i=0;i<t.size();i++)s[3].push_back(t[i]);
	t="ghi";for(int i=0;i<t.size();i++)s[4].push_back(t[i]);
	t="jkl";for(int i=0;i<t.size();i++)s[5].push_back(t[i]);
	t="mno";for(int i=0;i<t.size();i++)s[6].push_back(t[i]);
	t="pqrs";for(int i=0;i<t.size();i++)s[7].push_back(t[i]);
	t="tuv";for(int i=0;i<t.size();i++)s[8].push_back(t[i]);
	t="wxyz";for(int i=0;i<t.size();i++)s[9].push_back(t[i]);
	int n;cin>>n;
	for(;n--;)
	{
		cin>>t;
		string ans="";
		for(int i=0;i<t.size();i++)
		{
			int cnt=0,c=t[i]-'0';
			while(t[i]!='0')cnt++,i++;
			if(cnt)ans+=s[c][(cnt-1)%s[c].size()];
		}
		cout<<ans<<endl;
	}
}

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

string data[10]={
	"",
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz"
};
int main(){
	int t;
	cin>>t;
	while(t>0){
		t--;
		string str;
		cin>>str;
		string ans;
		int counts=0;
		for(int i=0;i<str.size();i++){
			if(str[i]=='0'){
				if(counts)ans+=data[str[i-1]-'0'][(counts-1)%data[str[i-1]-'0'].size()];
				counts=0;
			}
			else counts++;
		}
		cout<<ans<<endl;
	}
}

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,d;
  char b[1025];
  cin>>a;
  for(int i=0;i<a;i++){
    scanf("%s",b);
    c=strlen(b);
    for(int j=0;j<c;j++){
      if(b[j]!='0')count++;
      else
	if(b[j-1]!=0 && count){
	  d=b[j-1]-'0';
	  if(d==1)
	    cout<<m[d-1][(count-1)%5];
	  else if(d==7 || d==9)
	    cout<<m[d-1][(count-1)%4];
	  else
	    cout<<m[d-1][(count-1)%3];
	  count=0;
	}
    }
    cout<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a,d[9];
	d[0]=".,!?",d[1]="abc",d[2]="def",d[3]="ghi",d[4]="jkl";
	d[5]="mno",d[6]="pqrs",d[7]="tuv",d[8]="wxyz";
	for(int i=0;i<n;i++){
		cin>>a;
		int count=-1;
		for(int j=0;j<a.size();j++){
			if(j!=0){
			if(a[j]=='0'&&a[j-1]!='0'){
				cout<<d[a[j-1]-'1'][count];
			    count=-1;
			}
			}
			if(a[j]!='0')
			    count++;
			if(a[j]=='1'||a[j]=='7'||a[j]=='9')
				count%=4;
			else
				count%=3;
		}
		cout<<endl;
	}
    return 0;
}

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

char set1[5] = {'.',',','!','?',' '};
char set2[3] = {'a','b','c'};
char set3[3] = {'d','e','f'};
char set4[3] = {'g','h','i'};
char set5[3] = {'j','k','l'};
char set6[3] = {'m','n','o'};
char set7[4] = {'p','q','r','s'};
char set8[3] = {'t','u','v'};
char set9[4] = {'w','x','y','z'};

char slove(char key, int count){
	switch(key){
		case '1':
			count%=5;
			return set1[count];
			break;
			
		case '2':
			count%=3;
			return set2[count];
			break;
			
		case '3':
			count%=3;
			return set3[count];
			break;
			
		case '4':
			count%=3;
			return set4[count];
			break;
			
		case '5':
			count%=3;
			return set5[count];
			break;
			
		case '6':
			count%=3;
			return set6[count];
			break;
			
		case '7':
			count%=4;
			return set7[count];
			break;
			
		case '8':
			count%=3;
			return set8[count];
			break;
			
		case '9':
			count%=4;
			return set9[count];
			break;
			
		default:
			cout << "test" << endl;
			return 0;
	}
}


int main(){
	int n;
	while(cin>>n){
		string s;
		for(int i=0; i<n; i++){
			cin >> s;
			string ans="";
			for(string::size_type j=0; j<s.size(); j++){
				int count=0;
				char c=s[j];
				while(c!='0'){
					count++;
					c=s[j+count];
				}
				if(count!=0)
					ans += slove(s[j+count-1], count-1);
				

				j+=count;
			}
			cout << ans << endl;
		}
		
	}
	return 0;
}