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 <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))

using namespace std;
using LL=long long;

int pk[10];
char D[10][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,curk=0;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
        string r;
        Mset(pk,0);
        cin>>s;
        for(int j=0;j<s.size();j++){
            switch(s[j]){
                case '1':
                    curk=1;
                    pk[1]++;
                    if(pk[1]>5) pk[1]=1;
                    break;
                case '2':
                    curk=2;
                    pk[2]++;
                    if(pk[2]>3) pk[2]=1;
                    break;
                case '3':
                    curk=3;
                    pk[3]++;
                    if(pk[3]>3) pk[3]=1;
                    break;
                case '4':
                    curk=4;
                    pk[4]++;
                    if(pk[4]>3) pk[4]=1;
                    break;
                case '5':
                    curk=5;
                    pk[5]++;
                    if(pk[5]>3) pk[5]=1;
                    break;
                case '6':
                    curk=6;
                    pk[6]++;
                    if(pk[6]>3) pk[6]=1;
                    break;
                case '7':
                    curk=7;
                    pk[7]++;
                    if(pk[7]>4) pk[7]=1;
                    break;
                case '8':
                    curk=8;
                    pk[8]++;
                    if(pk[8]>3) pk[8]=1;
                    break;
                case '9':
                    curk=9;
                    pk[9]++;
                    if(pk[9]>4) pk[9]=1;
                    break;
                case '0':
                    if(curk){
                        r+=D[curk][pk[curk]-1];
                        pk[curk]=0;
                        curk=0;
                    }
            }
        }
        cout<<r<<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 = '0';
    for (int j = 0; j < s.size(); ++j)
    {
      if (s[j] == '0')
      {
        if (c == '0')
          continue;
        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 <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    string button[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

    int d;
    cin >> d;

    while(--d >= 0){
        string s;
        cin >> s;
        int n = s.size();

        string ret;
        int i = 0;
        while(i < n){
            char c = s[i];
            if(c == '0'){
                ++ i;
                continue;
            }

            int m = -1;
            while(i < n && c == s[i]){
                ++ m;
                ++ i;
            }
            ret += button[c-'1'][m%button[c-'1'].size()];
        }

        cout << ret << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    vector<vector<char>> ten_key(10);
    ten_key[0] = {'\n'};
    ten_key[1] = {' ', '.', ',', '!','?'};
    ten_key[2] = {'c', 'a', 'b'};
    ten_key[3] = {'f', 'd', 'e'};
    ten_key[4] = {'i', 'g', 'h'};
    ten_key[5] = {'l', 'j', 'k'};
    ten_key[6] = {'o', 'm', 'n'};
    ten_key[7] = {'s', 'p', 'q', 'r'};
    ten_key[8] = {'v', 't', 'u'};
    ten_key[9] = {'z', 'w', 'x', 'y'};

    int N; cin >> N;
    while(N--){
        string S; cin >> S;
        string ans = "";
        int num = 0, cnt = 0;
        for(auto& c : S){
            if(c == '0' && num != 0){
                ans += ten_key[num][cnt];
                num = 0;
                cnt = 0;
            } else {
                num = int(c - '0');
                cnt = (cnt + 1) % ten_key[num].size();
            }
        }

        cout << ans << endl;
    }
}

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

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

vector<string> button = {".,!?",
           "abc",
           "def",
           "ghi",
           "jkl",
           "mno",
           "pqrs",
           "tuv",
           "wxyz"};


int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    int cnt = 0;
    for(int j = 0; j < s.size(); j++){
      if(s[j] == '0'){
        if(cnt != 0){
          int num = s[j-1] - '0';
          char c = button[num - 1][(cnt-1)%button[num-1].size()];
          cout << c;
          cnt = 0;
        }
      }else{
        cnt++;
      }
    }
    cout << endl;
  }
}