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> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
#include <math.h>
#include <sstream>

using namespace std;
int main(void){
    int n;
    cin>>n;
    string out1=".,!? ";
    string out2="abc";
    string out3="def";
    string out4="ghi";
    string out5="jkl";
    string out6="mno";
    string out7="pqrs";
    string out8="tuv";
    string out9="wxyz";
    for(int s=0;s<n;s++){
        string in;
        cin>>in;
        int cnt=0;
        for(int i=0;i<in.length();i++){
            switch (in[i]-'0') {
                case 0:
                    switch (in[i-1]-'0') {
                        case 1:
                            if(cnt<=5)cout<<out1[cnt-1];
                            else cout<<out1[cnt%5-1];
                            break;
                        case 2:
                            if(cnt<=3)cout<<out2[cnt-1];
                            else cout<<out2[cnt%3-1];
                            break;
                        case 3:
                            if(cnt<=3)cout<<out3[cnt-1];
                            else cout<<out3[cnt%3-1];
                            break;
                        case 4:
                            if(cnt<=3)cout<<out4[cnt-1];
                            else cout<<out4[cnt%3-1];
                            break;
                        case 5:
                            if(cnt<=3)cout<<out5[cnt-1];
                            else cout<<out5[cnt%3-1];
                            break;
                        case 6:
                            if(cnt<=3)cout<<out6[cnt-1];
                            else cout<<out6[cnt%3-1];
                            break;
                        case 7:
                            if(cnt<=4)cout<<out7[cnt-1];
                            else cout<<out7[cnt%4-1];
                            break;
                        case 8:
                            if(cnt<=3)cout<<out8[cnt-1];
                            else cout<<out8[cnt%3-1];
                            break;
                        case 9:
                            if(cnt<=4)cout<<out9[cnt-1];
                            else cout<<out9[cnt%4-1];
                            break;
                    }
                    cnt=0;
                    break;
                default:
                    cnt++;
                    break;
            }
        }
        cout<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#include <tuple>
#include <iterator>
using namespace std;
using ll = long long;

char t[][5] = {
    {},
    {'.', ',', '!', '?', ' '},
    {'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'}};

int main()
{
  int n;
  cin >> n;
  vector<string> ans;
  for (int i = 0; i < n; ++i)
  {
    string s;
    cin >> s;
    string sum = "";
    int cnt = 0;
    char c;
    for (int j = 0; j < s.size(); ++j)
    {
      if (s[j] == '0')
      {
        if ((c - '0') == 1)
          sum += t[c - '0'][(cnt - 1) % 5];
        else if ((c - '0') == 7 || (c - '0') == 9)
          sum += t[c - '0'][(cnt - 1) % 4];
        else
          sum += t[c - '0'][(cnt - 1) % 3];
        cnt = 0;
        c = '0';
      }
      else
      {
        c = s[j];
        cnt++;
      }
    }
    ans.push_back(sum);
  }
  for (auto &e : ans)
    cout << e << endl;

  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 == '7')
				{
					if (cnt % 4 == 0) v.push_back('s');
					else v.push_back('p' + cnt % 4 - 1);
				}
				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 <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)

void b(int a,int count){
  if(a == 1){
    if(count%5==1) cout <<".";
    else if(count%5==2) cout <<",";
    else if(count%5==3) cout <<"!";
    else if(count%5==4) cout <<"?";
    else if(count%5==0) cout <<" ";

  }
  else if(a == 2){
    if(count%3==1) cout <<"a";
    else if(count%3==2) cout <<"b";
    else if(count%3==0) cout <<"c";
  }
  else if(a == 3){
    if(count%3==1) cout <<"d";
    else if(count%3==2) cout <<"e";
    else if(count%3==0) cout <<"f";
  }
  else if(a == 4){
    if(count%3==1) cout <<"g";
    else if(count%3==2) cout <<"h";
    else if(count%3==0) cout <<"i";
  }
  else if(a == 5){
    if(count%3==1) cout <<"j";
    else if(count%3==2) cout <<"k";
    else if(count%3==0) cout <<"l";
  }
  else if(a == 6){
    if(count%3==1) cout <<"m";
    else if(count%3==2) cout <<"n";
    else if(count%3==0) cout <<"o";
  }
  else if(a == 7){
    if(count%4==1) cout <<"p";
    else if(count%4==2) cout <<"q";
    else if(count%4==3) cout <<"r";
    else if(count%4==0) cout <<"s";
  }
  else if(a == 8){
    if(count%3==1) cout <<"t";
    else if(count%3==2) cout <<"u";
    else if(count%3==0) cout <<"v";
  }
  else if(a == 9){
    if(count%4==1) cout <<"w";
    else if(count%4==2) cout <<"x";
    else if(count%4==3) cout <<"y";
    else if(count%4==0) cout <<"z";
  }
  return;
}


int main(){

  int n;
  cin >> n;

  rep(i,0,n){
    string s;
    cin >> s;

    char pre[] = "0\0";
    pre[0]=s[0];
    int count = 0;
    rep(i,0,s.size()){

      if(pre[0] == s[i]){
	count++;
      }
      else{
	int bo = atoi(pre);
	b(bo,count);
	count=1;
	pre[0]=s[i];
      }
    }
    cout << endl;
  }
  return 0;
}