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<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;

int N;
string wa[10]={ "",
		".,!? ",
		"abc",
		"def",
		"ghi",
		"jkl",
		"mno",
		"pqrs",
		"tuv",
		"wxyz"};
vector<char> ans;
int main(){
  cin >> N;
  for(int t=0;t<N;t++){
    string s;
    cin >> s;
    int pr = 0;
    int jd = 0;
    ans.clear();
    for(int i=0;i<(int)s.size();i++){
      int id = s[i]-'0';
      if( id == 0 ){
	//	cout << wa[pr][jd] << endl;
	if( pr!=0 ) ans.push_back(wa[pr][jd]);
      } else if( pr != id ){
	jd = 0;
      } else {
	jd = (jd+1)%(int)wa[id].size();
      }
      pr = id;
    }
    for(int i=0;i<(int)ans.size();i++){
      cout << ans[i];
    }
    cout << endl;
  }
}

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;
                        case 0:
                            break;
                    }
                    cnt=0;
                    break;
                default:
                    cnt++;
                    break;
            }
        }
        if(in=="0")cout<<"";
        else cout<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  char str[100000]={};
  char moji[10][6]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  int i;
  int n;

  cin>>n;
  rep(i,n){
    cin>>str;
    int len=strlen(str);
    int j=0;
    while(j<len){
      int num=0;
      while(str[j]!='0'){
	j++;
	num++;
      }
      if(j==0){
	j++;
	continue;
      }
      a=str[j-1]-'0';
      if(a==1)
	cout<<moji[1][(num-1)%5];
      else if((a>1 && a<7)|| a==8)
	cout<<moji[a][(num-1)%3];
      else if(a==7 || a==9)
	cout<<moji[a][(num-1)%4];
      j++;
    }
    cout<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
vector<vector<char> > phone = {
    {'\0'},
    {' ', '.', ',', '!', '?'},
    {'c', 'a', 'b'},
    {'f', 'd', 'e'},
    {'i', 'g', 'h'},
    {'l', 'j', 'k'},
    {'o', 'm', 'n'},
    {'s', 'p', 'q', 'r'},
    {'v', 't', 'u'},
    {'z', 'w', 'x', 'y'}
};

int main() {
    int n; cin >> n;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        int k = 0, kl = 0;
        for (char c : s) {
            if (c - '0' == 0) {
                cout << phone[kl][k];
                k = 0;
                kl = 0;
            } else {
                kl = c - '0';
                k = (k+1) % phone[kl].size();
            }
        }
        cout << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int n; cin >> n;
    while (n--) {
        string s; cin >> s;
        char key = s[0], befkey = s[0];
        int c = 0;
        string table[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        rrep(i, 1, s.size()) {
            key = s[i];
            if (key == '0' && befkey != '0') cout << table[befkey - '0'][c];
            if (key == befkey) {c++; if (table[befkey - '0'][c] == '\0') c = 0;}
            else c = 0;
            befkey = key;
        }
        cout << endl;
    }
}