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 <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::stoi;

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<stdio.h>
#include<string>
using namespace std;
string table[]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
char str[128];
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		scanf("%s",str);
		int renzoku=0;
		char now='0';
		for(int i=0;str[i];i++){
			if(now!=str[i]){
				if(now!='0'){
					printf("%c",table[now-'0'][(renzoku-1)%table[now-'0'].size()]);
				}
				renzoku=1;
				now=str[i];
			}else renzoku++;
		}
		printf("\n");
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    vvc chartable;
    chartable.push_back({'.',',','!','?',' '});
    chartable.push_back({'a','b','c'});
    chartable.push_back({'d','e','f'});
    chartable.push_back({'g','h','i'});
    chartable.push_back({'j','k','l'});
    chartable.push_back({'m','n','o'});
    chartable.push_back({'p','q','r','s'});
    chartable.push_back({'t','u','v'});
    chartable.push_back({'w','x','y','z'});

    int n;
    cin >> n;
    REP(i, n) {
        string s;
        cin >> s;
        int a = -1, b = 0;
        REP(j, SZ(s)) {
            if (s[j] == '0') {
                if (a != -1) {
                    cout << chartable[a][b];
                }
                a = -1;
            } else {
                if (a != s[j] - '0' - 1) {
                    a = s[j] - '0' - 1;
                    b = -1;
                }
                b = (b + 1) % SZ(chartable[a]);
            }
        }
        cout << endl;
    }
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 100000000
#define EPS 1e-9

using namespace std;

typedef long long ll; 

#define MAX_N 31
#define MAX_M 501

int N;

string alpha[10];

vector<string> ans_list;

int main(){
  
  cin >> N;

  alpha[1] = ".,!? ";
  alpha[2] = "abc";
  alpha[3] = "def";
  alpha[4] = "ghi";
  alpha[5] = "jkl";
  alpha[6] = "mno";
  alpha[7] = "pgrs";
  alpha[8] = "tuv";
  alpha[9] = "wxyz";

  while(N > 0){
    N--;
    string str, ans;
    cin >> str;
    for(int i = 0; i < str.length(); i++){
      if(str[i] == '0')
	continue;
      int num = 0;
      for(int e = i+1; e < str.length(); e++){
	if(str[i] != str[e]){
	  num = e - i;
	  break;
	}
      }
      ans += alpha[str[i] - '0'][(num-1) % alpha[str[i] - '0'].length()];
      i += num;
    }
    ans_list.push_back(ans);
  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }

  return 0;
  
}

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

string one=".,!? ";
string les=".adgjmptw";

int main()
{
	int N;
	cin >> N;
	while(N--)
	{
		string s;
		cin >> s;
		char n='_';
		int l=0;
		for(int i=0; i<s.size(); i++)
		{
			int d=s[i]-'0';
			if(d==0)
			{
				if(n=='_') continue;
				if(n=='.') cout << one[l];
				else cout << (char)(n+l);
				n='_';
				l=0;
			}
			else
			{
				if(n=='_')
				{
					n=les[d-1];
				}
				else
				{

					int mod=3;
					if(d==1) mod=5;
					if(d==7||d==9) mod=4;
					l++;
					l%=mod;
				}
			}
		}

		cout << endl;
	}
}