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++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int T; cin >> T;
    const vector<vector<char>> data = {
        {},
        {'.',',','!','?',' '},
        {'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'}
    };
    while (T--) {
        string S; cin >> S;
        int N = S.size();
        string ans = "";
        int cnt = 0;
        rep(i,N) {
            if (S[i] != '0') cnt++;
            else {
                if (cnt != 0) {
                    ans += data[S[i-1]-'0'][(cnt-1)%data[S[i-1]-'0'].size()];
                    cnt = 0;
                }
            }
        }

        cout << ans << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<pair<int,int> > vpii(80);
string num;
void print(int s,int m,int f){
  switch(f-48){
  case 1:switch(s){
    case 1:cout<<'.';break; case 2:cout<<',';break; case 3:cout<<'!';break;case 4:cout<<'?';break; case 5:cout<<" ";break;}break;
  case 2:switch(s){
    case 1:cout<<'a';break; case 2:cout<<'b';break; case 3:cout<<'c';break;}break;
  case 3:switch(s){
    case 1:cout<<'d';break;case 2:cout<<'e';break;case 3:cout<<'f';break;}break;
  case 4:switch(s){
    case 1:cout<<'g';break;case 2:cout<<'h';break;case 3:cout<<'i';break;} break;
case 5:switch(s){
    case 1:cout<<'j';break;case 2:cout<<'k';break;case 3:cout<<'l';break;} break;
case 6:switch(s){
    case 1:cout<<'m';break;case 2:cout<<'n';break;case 3:cout<<'o';break;} break;
case 7:switch(s){
    case 1:cout<<'p';break;case 2:cout<<'q';break;case 3:cout<<'r';break;case 4:cout<<'s';break;} break;
case 8:switch(s){
    case 1:cout<<'t';break;case 2:cout<<'u';break;case 3:cout<<'v';break;}break; 
case 9:switch(s){
    case 1:cout<<'w';break;case 2:cout<<'x';break;case 3:cout<<'y';break;case 4:cout<<'z';break;}break;
  default :break; 
  }
}
void dfs(int m,int d,int w,char f){
  if(w==d){
    print(d,m,f);
  }
  dfs(m,d,w+1,f);
}
int main(){
  int k=0,l=0,n;
  cin >> n;
  for(int q=0;q<n;q++){
    cin >> num;
    int a;
    for(int i=0;i<num.size();i++){
      if(i==0)
	a=num[0];
      k++;
      if(i!=0&&num[i]=='0' &&num[i-1]=='0'){
	k=0;
	continue;
      }
      if(num[i]!='0')
	a=num[i];
      cout<<a<<k<<endl;
     
      if(num[i]=='0'){
	vpii[l]=make_pair(a,k-1);
	cout<<vpii[l].first<<vpii[l].second<<endl;
	l++;
	k=0;
      }
    }
    for(int j=0;j<l;j++){
      int w=0;
      dfs(j,vpii[j].second,w,vpii[j].first);
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cstdlib>

using namespace std;

char num1[5]={'.', ',', '!', '?', ' '};
char num2[]="abc", num3[]="def", num4[]="ghi", num5[]="jkl", num6[]="mno", num7[]="pqrs", num8[]="tuv", num9[]="wxyz";

char func(int x, int y);

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int c1, c2, c3=0;
		char c;
		c1 = getchar();
		while(1){
			c1 = getchar();
			if(c1 == '\n'){
				cout << endl;
				break;
			} else if(c1 == '0'){
				c = func(c2, c3);
				cout << c;
				c3 = 0;
			} else {
				if(c1 == c2) c3++;
				else {
					c1 = c1 - '0';
					c2 = c1;
					c3++;
				}
			}
		}
	}
	return 0;
}

char func(int x, int y)
{
	int z;
	if(x == 1) return num1[(y-1)%5];
	else if(x == 2) return num2[(y-1)%3];
	else if(x == 3) return num3[(y-1)%3];
	else if(x == 4) return num4[(y-1)%3];
	else if(x == 5) return num5[(y-1)%3];
	else if(x == 6) return num6[(y-1)%3];
	else if(x == 7) return num7[(y-1)%4];
	else if(x == 8) return num8[(y-1)%3];
	else return num9[(y-1)%4];
}

C++: // Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

void play(string str){
    string mas[]={"x",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    int lng = 0;
    
    for(int i = 0; i < str.size() ; i++){
        if(str[i] == '0'){
            if(lng!=0){
                //cout << (lng-1) << " " << mas[str[i-1]-'0'].size() << endl;
                cout << mas[str[i-1]-'0'][(lng-1)%mas[str[i-1]-'0'].size()];
                lng = 0;
            }
        }
        else lng++;
    }       
}

main(){
    int t;
    string str;
    
    cin >> t;
    
    while(t--){
        cin >> str;
        
        play(str);
    }
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}