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>

using namespace std;

int main(){
	string s;
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		char a;
		cin >> s;
		char t = '~';
		for(int j = 0; j < s.length(); ++j){
			a = s[j];
			switch(a){
				case '1':
					if(t == '~' || t == ' '){
						t = '.';
					}else if(t == '.'){
						t = ',';
					}else if(t == ','){
						t = '!';
					}else if(t == '!'){
						t = '?';
					}else if(t == '?'){
						t = ' ';
					}
					break;
				case '2':
					if(t == '~' || t == 'c'){
						t = 'a';
					}else{
						t++;
					}
					break;
				case '3':
					if(t == '~' || t == 'f'){
						t = 'd';
					}else{
						t++;
					}
					break;
				case '4':
					if(t == '~' || t == 'i'){
						t = 'g';
					}else{
						t++;
					}
					break;
				case '5':
					if(t == '~' || t == 'l'){
						t = 'j';
					}else{
						t++;
					}
					break;
				case '6':
					if(t == '~' || t == 'o'){
						t = 'm';
					}else{
						t++;
					}
					break;
				case '7':
					if(t == '~' || t == 's'){
						t = 'p';
					}else{
						t++;
					}
					break;
				case '8':
					if(t == '~' || t == 'v'){
						t = 't';
					}else{
						t++;
					}
					break;
				case '9':
					if(t == '~' || t == 'z'){
						t = 'w';
					}else{
						t++;
					}
					break;
				case '0':
					if(t != '~'){
						cout << t;
						t = '~';
					}
					break;
			}
		}
		cout << endl;
	}
}

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

#include<vector>

int main(){
	int n;
	cin>>n;
	
	/*
	char a1[]={".",",","!","?"," "};
	char a2[]={"a","b","c"};
	char a3[]={"d","e","f"};
	char a4[]={"g","h","i"};
	char a5[]={"j","k","l"};
	char a6[]={"m","n","o"};
	char a7[]={"p","q","r","s"};
	char a8[]={"t","u","v"};
	char a9[]={"w","x","y","z"};
	*/
	
	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";
	
	for(int k=0;k<n;k++){
		string s;
		cin>>s;
		int cnt=0;
		int mj=0;
		for(int i=0;i<s.size();i++){
			if(s[i]-'0'==0){
				if(mj!=0){
				cout<<a[mj][cnt%a[mj].size()];
				cnt=0;
				mj=0;
				}
			}else{
				if(s[i]-'0'==mj){
					cnt++;
				}else{
					mj=s[i]-'0';
				}
			}
		}
		cout<<endl;
	}
	return 0;
}

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

char mes(char c){
    int n = c -'0';
    if(n==2)return 'a';
    else if(n==3)return 'd';
    else if(n==4)return 'g';
    else if(n==5)return 'j';
    else if(n==6)return 'm';
    else if(n==7)return 'p';
    else if(n==8)return 't';
    else return 'w';
}


int main(){
    long long n;
    cin >> n;
    for(int i=0;i<n;i++){
        string str;
        cin >> str;
        int cou = 1;    
        if(str[0]=='0')cou=0;
        for(int j=1;j<str.size();j++){
           if(str[j]=='0' && str[j-1]!='0'){
                    if(cou)cou--;
                    if(str[j-1]!='1'){
                        char a = mes(str[j-1]);
                        if(str[j-1]=='7'||str[j-1]=='9')printf("%c",a + (cou)%4);
                        else printf("%c",a+cou%3);
                    }else{
                       cou%=5;
                        if(!cou)cout << ".";
                        else if(cou==1)cout << ",";
                        else if(cou==2)cout << "!";
                        else if(cou==3)cout << "?";
                        else cout << " ";
                    }
                cou = 0;
           }else if(str[j]!='0'){
               cou++;
           }
        }
        cout << endl;
    }
}

C++: #include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;

int n;

string temp[]={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		string t[1000];
		bool flag=0;
		int now=0;
		for(int j=0;j<(int)s.length();j++){
			if(s[j]=='0'){
				if(flag){
					now++;
					t[now]="";
					flag=0;
				}
			}else{
				t[now]+=s[j];
				flag=1;
			}
		}
		string ans="";
		for(int j=0;j<now;j++){
			int index=t[j][0]-'1';
			int index2=t[j].length()%temp[index].length();
			if(index2==0)index2=temp[index].length()-1;
			else index2--;
			ans+=temp[index][index2];
		}
		cout<<ans<<"\n";
	}
	return 0;
}

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

char hyo[9][5];

char moji(int char_, int count);

int main(void)
{
	int i1,i2;
	char c = 'a';
	char cc;
	string s;
	int n;
	int m;
	int count;

	/* syokika */
	for(i1=0;i1<9;i1++){	
		for(i2=0;i2<5;i2++){
			hyo[i1][i2] = '1';
//			cout << hyo[i1][i2];
		}
//		cout << endl;
	}


	/* hyo sakusei */
	hyo[0][0] = '.';
	hyo[0][1] = ',';
	hyo[0][2] = '!';
	hyo[0][3] = '?';
	hyo[0][4] = ' ';


	for( i1=1; i1<9; i1++){
		for(i2=0; i2<4; i2++){
			
			if(i2 == 3) {

				if( i1 == 6 || i1 == 8) {}
				else continue;
			}

			hyo[i1][i2] = c;
			c++;
//			cout << hyo[i1][i2] << " ";
		}
//		cout << endl;
	}



	cin >> n;

	for(i2=0;i2<n;i2++){


	//	cout << "s?" << endl;
		cin >> s;

		count = 0;
		m = 0;
		for(i1=0;i1<s.size();i1++){
		

			if( s[i1]=='0'){
				if(m != 0){
					cc = moji(m,count);
					count = 0;
					m = 0;
				    cout << cc;
				}
			}
			else{

				c = s[i1];
				m = c - 48;
				count++;
			}
		}


	}

/*	i1 = 0;
	count = 0;
	for(i1=0;i1<10;i1++){

//		char_ = s[i1];
		count++;

		if(s[i1] == 0){
			c = moji(char_, count);
			count = 0;
		}
	}

*/

//	c = moji(4,2);
//	cout << c;

	return 0;

}


char moji(int char_, int count)
{

	int n;
	count--;
	if( char_ == 1){
		n = count%5;
	}
	else if( char_ == 7 || char_ == 9){
		n = count%4;
	}
	else {
		n = count%3;
	}

//	if(n==0){n++;}


	return hyo[char_-1][n];
}