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;
int main(){
  vector<char> a[10];
  vector<char> ans;
  a[0].push_back('.');
  a[0].push_back(',');
  a[0].push_back('!');
  a[0].push_back('?');
  a[0].push_back(' ');
  a[1].push_back('a');
  a[1].push_back('b');
  a[1].push_back('c');
  a[2].push_back('d');
  a[2].push_back('e');
  a[2].push_back('f');
  a[3].push_back('g');
  a[3].push_back('h');
  a[3].push_back('i');
  a[4].push_back('j');
  a[4].push_back('k');
  a[4].push_back('l');
  a[5].push_back('m');
  a[5].push_back('n');
  a[5].push_back('o');
  a[6].push_back('p');
  a[6].push_back('q');
  a[6].push_back('r');
  a[6].push_back('s');
  a[7].push_back('t');
  a[7].push_back('u');
  a[7].push_back('v');
  a[8].push_back('w');
  a[8].push_back('x');
  a[8].push_back('y');
  a[8].push_back('z');
  char x;
  int n;
  cin>>n;
  
  scanf("%c",&x);
  int memo=-1,count=-1,z=0;
  for(int i=0;i<n;i++){
    while(1){
      scanf("%c",&x);
      if('0'<=x &&x<='9'){
	z=x-'0';
	if(z!=0){
	  memo=z;
	  count++;
	}
	else{
	  memo--;
	  if(memo==-2){
	    memo=-1;
	    continue;
	  }
	  count%=a[memo].size();
	  cout<<a[memo][count];
	  memo=-1;
	  count=-1;
	}
      }
      else{
	cout<<endl;
      break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


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



int main(){
	int n;
	string s;
	cin>>n;
	rep(i,n){
		cin>>s;
		string a;
		rep(j,s.size()){
			if(s[j]!='0'){
				char c=t[s[j]-'0'][0];
				int k=0;
				while(1){
					j++;
					if(j>s.size())break;
					if(s[j]=='0'){
						a+=c;
						break;
					}
					k=(k+1)%t[s[j]-'0'].size();
					c=t[s[j]-'0'][k];
				}
			}
		}
		cout<<a<<endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

int key[10];

// プロトタイプ宣言
void Reset(void);
char Output(int);
// ここまで

int main(){
	Reset();

	int n;	cin>>n;
	for(int i=0;i<n;i++){
		string ans="";
		string s;
		cin>>s;
		for(int j=0;j<s.length();j++){
			int num=s[j]-'0';
			//printf("<%d>\n",num);

			if(num==0){
				for(int k=1;k<=9;k++){
					if(key[k]<0)continue;
					else ans+=Output(k);
				}
				Reset();
			}else{
				key[num]++;
			}
		}

		cout<<ans<<endl;
	}


	return 0;
}



void Reset(void){ for(int i=0;i<10;i++) key[i]=-1; }
char Output(int num){
	char word[10][5]={
		{'A','B','C','D','E'},// 使わない
		{'.',',','!','?',' '},
		{'a','b','c','F','G'},
		{'d','e','f','H','I'},
		{'g','h','i','J','K'},
		{'j','k','l','L','M'},
		{'m','n','o','N','O'},
		{'p','q','r','s','P'},
		{'t','u','v','Q','R'},
		{'w','x','y','z','S'}};

	int tmp=key[num];
	switch(num){
		case 1:
			tmp%=5;
			break;
		case 7:
		case 9:
			tmp%=4;
			break;
		default:
			tmp%=3;
			break;
	}

	return word[num][tmp];
}

C++: #include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  string tenkey[10] = {".,!? ",
                     "abc",
                     "def",
                     "ghi",
                     "jkl",
                     "mno",
                     "pqrs",
                     "tuv",
                     "wxyz"};
  cin >> n;

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    for (int j = 0; j < s.size(); j++) {
      int count = -1;
      int num = s[j] - '0';
      while (s[j] != '0') {
        count++;
        j++;
      }
      //cout << "num-1 = " << num-1 << endl;                                                                                                      
      //cout << "count = " << count << endl;                                                                                                      
      if (count >= 0) {
        //cout << "tenkey[num-1].size() = " << tenkey[num-1].size() << endl;                                                                      
        cout << tenkey[num-1][count % tenkey[num-1].size()];
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
    int n;
    char ans[100];
    char s[1100];
    int value;
    int h = 0,w,cnt;
    bool judge;
    char tmp[9][6] = {{".,!? "},{"abc"},{"def"},{"ghi"},{"jkl"},{"mno"},{"pqrs"},{"tuv"},
        {"wxyz"}};
    cin >> n;
    while(n--){
        value = 0;
        memset(ans,0,sizeof(ans));
        memset(s,0,sizeof(s));
        cin >> s;
        for(int i=0;i<strlen(s);i++){
            cnt = 0;
            h = 0;
            while(1){
                if(s[i] == '0') break;
                h = s[i]%'0';
                cnt++;  
                i++;
            }
            w = cnt-1;
            judge = false;
            switch (h-1){
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 7:
                    ans[value] = tmp[h-1][w%3];
                    judge = true;
                    break;
                case 6:
                case 8:
                    ans[value] = tmp[h-1][w%4];
                    judge = true;
                    break;
                case 0:
                    ans[value] = tmp[h-1][w%5];
                    judge = true;
            }
            if(judge) value++;
        }
        cout << ans << endl;
    }
}

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

int main()
{
	int n, p, cnt;
	string key[] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	string str;
	
	cin >> n;
	while (cin >> str) {
		for (char& c : str) {
			n = c - '0';
			if (n) {
				cnt++;
			} else {
				cout << key[p][(cnt-1) % key[n].size]
				cnt = 0;
			}
			p = n;
		}
		cout << endl;
	}
	
	return 0;
}