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 <bits/stdc++.h>
using namespace std;

char trans(char num, int i){
    if(num == '1'){
        if(i % 4 == 1) return ' ';
        else if(i % 4 == 2) return ',';
        else if(i % 4 == 3) return '!';
        else if(i % 4 == 0) return '?';
    }
    if(num == '2'){
        if(i % 3 == 1) return 'a';
        else if(i % 3 == 2) return 'b';
        else if(i % 3 == 0) return 'c';
    }
    if(num == '3'){
        if(i % 3 == 1) return 'd';
        else if(i % 3 == 2) return 'e';
        else if(i % 3 == 0) return 'f';
    }
    if(num == '4'){
        if(i % 3 == 1) return 'g';
        else if(i % 3 == 2) return 'h';
        else if(i % 3 == 0) return 'i';
    }
    if(num == '5'){
        if(i % 3 == 1) return 'j';
        else if(i % 3 == 2) return 'k';
        else if(i % 3 == 0) return 'l';
    }
    if(num == '6'){
        if(i % 3 == 1) return 'm';
        else if(i % 3 == 2) return 'n';
        else if(i % 3 == 0) return 'o';
    }
    if(num == '7'){
        if(i % 4 == 1) return 'p';
        else if(i % 4 == 2) return 'q';
        else if(i % 4 == 3) return 'r';
        else if(i % 4 == 0) return 's';
    }
    if(num == '8'){
        if(i % 3 == 1) return 't';
        else if(i % 3 == 2) return 'u';
        else if(i % 3 == 0) return 'v';
    }
    if(num == '9'){
        if(i % 4 == 1) return 'w';
        else if(i % 4 == 2) return 'x';
        else if(i % 4 == 3) return 'y';
        else if(i % 4 == 0) return 'z';
    }
    return '0';
}

int main(){
    int n;
    cin >> n;
    string s;

    for(int i = 0; i < n; i++){
        cin >> s;
        for(int j = 0; j < (int)s.size(); j++){
            int cnt = 0;
            if(s[j] == '0'){
                if(s[j-1] != '0'){
                    int k = j - 1;
                    cnt = 1;
                    while(s[k] == s[k - 1]){
                        cnt++;
                        k--;
                    }
                }
                cout << trans(s[j-1], cnt);
            }
        }
        cout << endl;
    }

    return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>


int main()
{
	int i,j,k;
	int n,m;
	int a[10]={0}; //押された回数
	int b[10]={0,4,3,3,3,3,3,4,3,4}; //割り算	 
	int c; //押されたボタン
	char d[5][10]={
	{'0','?','c','f','i','l','o','s','v','z'},
	{'0','.','a','d','g','j','m','p','t','w'},
	{'0',',','b','e','h','k','n','q','u','x'},
	{'0','!','0','0','0','0','0','r','0','y'},
	{'0',' ','0','0','0','0','0','0','0','0'}};
	char e[77];
	
	scanf("%d",&n);

	for(i=0;i<n;i++)
	{
		scanf("%s",e);
		for(j=0;j<strlen(e);j++)
		{
			if(e[j]=='0'){
				printf("%c",d[a[c]%b[c]][c]);
				a[c]=0;
			}else
			{
				if(e[j]=='1')c=1;
				else if(e[j]=='2')c=2;
				else if(e[j]=='3')c=3;
				else if(e[j]=='4')c=4;
				else if(e[j]=='5')c=5;
				else if(e[j]=='6')c=6;
				else if(e[j]=='7')c=7;
				else if(e[j]=='8')c=8;
				else if(e[j]=='9')c=9;
				a[c]++;
			}
		}
		printf("\n");
	}

	return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s
typedef pair<int, int> P;

char sym[] = { ' ','.', ',', '!','?' };
char alp[] = { '*', '*', 'a', 'd', 'g', 'j', 'm', 'p', 't' };

int main()
{
	int n;
	cin >> n;
	REP(k, n)
	{
		vector<char> v;
		string s;
		cin >> s;
		int cnt = 0;
		char buf = '0';
		REP(i, s.size())
		{
			if (s[i] == '0')
			{
				if (buf == '0') continue;
				else if (buf == '1') v.push_back(sym[cnt % 5]);
				else if (buf == '9')
				{
					if (cnt % 4 == 0) v.push_back('z');
					else v.push_back('w' + cnt % 4 - 1);
				}
				else
				{
					if (cnt % 3 == 0) v.push_back(alp[buf - '0'] + 2);
					else v.push_back(alp[buf - '0'] + cnt % 3 - 1);
				}
				cnt = 0;
				buf = '0';
			}
			else
			{
				buf = s[i];
				cnt++;
			}
		}
		REP(i, v.size()) cout << v[i];
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n;
	string ans="";
	string s;
	string y=".,!? abcdefghijklmnopqrstuvwxyz";
	int x,count=0;
	cin>>n;
	for(int j=0;j<n;j++){
		ans="";
		cin>>s;
		for(int i=0;i<s.size();i++){
			if(s[i] == '0' && count==0){
				//cout<<"C"<<endl;
				continue;
			}
			else if(s[i] != '0'){
				x=s[i]-'0';
				count++;
				//cout<<"B"<<endl;
			}
			else if(s[i] == '0' && count!= 0) {
				if(x==1){
					ans=ans+y[(count-1)%5];
				}
				if(x==2){
					ans=ans+y[5+(count-1)%3];
				}
				if(x==3){
					ans=ans+y[8+(count-1)%3];
				}
				if(x==4){
					ans=ans+y[11+(count-1)%3];
				}
				if(x==5){
					ans=ans+y[14+(count-1)%3];
				//	cout<<"A"<<endl;
				}
				if(x==6){
					ans=ans+y[17+(count-1)%3];
				}
				if(x==7){
					ans=ans+y[20+(count-1)%4];
				}
				if(x==8){
					ans=ans+y[24+(count-1)%3];
				}
				if(x==9){
					ans=ans+y[27+(count-1)%4];
				}
				count=0;
			}
			if(count!=0 && i==s.size()-1){
				if(x==1){
					ans=ans+y[(count-1)%5];
				}
				if(x==2){
					ans=ans+y[5+(count-1)%3];
				}
				if(x==3){
					ans=ans+y[8+(count-1)%3];
				}
				if(x==4){
					ans=ans+y[11+(count-1)%3];
				}
				if(x==5){
					ans=ans+y[14+(count-1)%3];
				//	cout<<"A"<<endl;
				}
				if(x==6){
					ans=ans+y[17+(count-1)%3];
				}
				if(x==7){
					ans=ans+y[20+(count-1)%4];
				}
				if(x==8){
					ans=ans+y[24+(count-1)%3];
				}
				if(x==9){
					ans=ans+y[27+(count-1)%4];
				}
				count=0;
			}

		}
		cout<<ans<<endl;
	}
	return 0;
}