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>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    char ans[][10] = {
        {'\0'},
        {'.',',','!','?',' '},
        {'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'}
    };
    ll n; cin >> n;
    rep(i,n){
        string s(100000,0);
        cin >> s;
        int temp = 0;
        int counter =-1 ;
        for(int k = 0;k<(int)s.size();k++){
            int now = int(s[k]-48);
            if(k == 0){temp = now;counter++;}
            else if(now != 0){
                temp = now;counter++;}
            if(now == 0){
                if(temp  == 9 || temp == 7)
                    counter%=4;
                else if(temp != 1&& temp != 7 && temp!= 9)
                    counter%=3;
                else if(temp == 1)
                    counter %=5;
                cout << ans[temp][counter];
                temp = 0;counter =-1;;
            }
        }
        cout << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(){
  string kigo = ".,!? ";
  string a = "abc";
  string d = "def";
  string g = "ghi";
  string j = "jkl";
  string m = "mno";
  string p = "pqrs";
  string t = "tuv";
  string w = "wxyz";
  string syu;
  int keta,n,count;
  int flag1 = 0;
  int flag2 = 0;
  cin >> n;
  string nn;
  for(int i = 0; i < n;i++){
    cin >> nn;
    syu = syu.empty();
    for(int i = 0; i < nn.length();i++){
      if(nn[i] == '1'){
        flag1 = 1;
        flag2 += 1;
      }else if(nn[i] == '2'){
        flag1 = 2;
        flag2 += 1;
      }else if(nn[i] == '3'){
        flag1 = 3;
        flag2 += 1;
      }else if(nn[i] == '4' ){
        flag1 = 4;
        flag2 += 1;
      }else if(nn[i] == '5'){
        flag1 = 5;
        flag2 += 1;
      }else if(nn[i]== '6'){
        flag1 = 6;
        flag2 += 1;
      }else if(nn[i] == '7'){
        flag1 = 7;
        flag2 += 1;
      }else if(nn[i] == '8'){
        flag1 = 8;
        flag2 += 1;
      }else if(nn[i] == '9'){
        flag1 = 9;
        flag2 += 1;
      }else if(nn[i] == '0'){
        if(flag1 == 0){
        }else{
          flag2 -= 1;
          if(flag1 == 1){
            syu += kigo[(flag2)%5];
            flag1 = 0;
          }else if(flag1 == 2){
            syu += a[flag2%3];
            flag1 = 0;
          }else if(flag1 == 3){
            syu += d[flag2%3];
            flag1 = 0;
          }else if(flag1 == 4){
            syu += g[flag2%3];
            flag1 = 0;
          }else if(flag1 == 5){
            syu += j[flag2%3];
            flag1 = 0;
          }else if(flag1 == 6){
            syu += m[flag2%3];
            flag1 = 0;
          }else if(flag1 == 7){
            syu += p[flag2%4];
            flag1 = 0;
          }else if(flag1 == 8){
            syu += t[flag2%3];
            flag1 = 0;
          }else if(flag1 == 9){
            syu += w[flag2%4];
            flag1 = 0;
          }
          flag2 = 0;
        }
      }
    }
      cout << syu << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

string s[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqls", "tuv", "wxyz"};

int main(void){
	int n;
	cin >> n;
	rep(k,n){
		string L;
		cin >> L;
		int type = 0;
		int count = 0;
		char put = '@';
		for(int i = 0; i < L.size(); i++){
			if(L[i] == '0'){
				if(put == '@')continue;
				cout << put;
				put = '@';
				type = 0;
				count = 0;
				continue;
			}
			type = L[i]-'0';
			count++;
			put = s[type-1][(count-1)%s[type-1].size()];
		}
		cout << endl;
	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

C++: #include <string>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    while(n--){
    string chs[10];
    chs[1]=".,!? ";
    chs[2]="abc";
    chs[3]="def";
    chs[4]="ghi";
    chs[5]="jkl";
    chs[6]="mno";
    chs[7]="pqrs";
    chs[8]="tuv";
    chs[9]="wxyz";

    string res;
    string s;
    cin>>s;
    int idx=0;
    int cnt=0;
    for(int i = 0; i < s.size(); i++){
        int num=s[i]-'0';
        if(num==0){
            if(idx!=0){
                res+=chs[idx][cnt];
                idx=0;
                cnt=-1;
            }
        }
        else{
            if(idx==num)
                cnt=(cnt+1)%(chs[idx].size());
            else{
                if(idx!=0)
                    res+=chs[idx][cnt];
                idx=num;
                cnt=0;
            }
        }
    }
    if(idx!=0)
        res+=chs[idx][cnt];
    cout<<res<<endl;
    }

    return 0;
}