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<cstdio>
using namespace std;

char data[10][5] = {'E','E','E','E','E',
		    '.', ',', '!' ,'?' ,' ',
		    'a', 'b', 'c', 'E', 'E',
		    'd','e','f','E','E',
		    'g','h','i','E','E',
		    'j','k','l','E','E',
		    'm','n','o','E','E',
		    'p','q','r','s','E',
		    't','u','v','E','E',
		    'w','x','y','z','E'};

char in;
int col=-1, row=0;
int num;
int state = 0;

int main(){
  int N;
  cin >> N;
  while(N--){
    cin.ignore();
    while(scanf("%c",&in) != EOF){
     
      if(in == '0'){
	if(col == -1) col++;
	if(row >= 2 && row <= 6 || row == 8) num = 3;
	else if(row == 1) num = 5;
	else num = 4;
	
	if(data[row][col%num] != 'E'){
	  cout << data[row][col%num];
	  state = 1;
      }
	col = -1;
	row = 0;
      }else{
	col++;
	row=in-48;
      }
      if(in == '\n'){
	if(state == 1) cout << endl;
	state = 0;
      col = -1;
      row = 0;
      }
      
    }
    if(data[row][col%num] != 'E'){
      cout << data[row][col%num];
      //state = 1;
    }
    if(state == 1) cout << endl;
  }
    return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

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

int main() {
	int n; cin >> n; cin.ignore();
	for (int i = 0; i < n; i++) {
		string s; getline(cin, s);
		int cnt = -1;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] != '0')cnt++;
			else if (cnt != -1) {
				printf("%c", b[s[j - 1] - '0'][cnt%b[s[j - 1] - '0'].size()]);
				cnt = -1;
			}
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
    int N;
    char c;
    char alpha[10]={'.','.','a','d','g','j','m','p','t','w'};
    char alpha1[5]={' ','.',',','!','?'};
    cin>>N;
    getchar();
    while(N--){
        int cnt=0,before,now=0;
        while(c=getchar(),c!='\n'){
            before = now;
            now = c-'0';
            //printf("before=%d , now=%d\n",before,now);
            if(now!=0)cnt++;
            else if(before==1){
                printf("%c",alpha1[cnt%5]);
                cnt=0;
            }else if(before!=0){
                printf("%c",alpha[before]+(cnt-1)%(before==7||before==9 ? 4 : 3));
                cnt=0;
            }
        }
        cout<<endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
int main(void){

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

    int n; scanf("%d",&n);
    for(int i = 0;i < n;i++){
        char in[10000];
        scanf("%s",in);
        int cnt = -1;
        for(int i = 0;i < strlen(in);i++){
            if(in[i] == '0'){
                if(cnt == -1) continue;

                if(in[i-1] == '1'){
                    cnt %= 5;
                }
                else if(in[i-1] == '9'){
                    cnt %= 6;
                }
                else{
                    cnt %= 3;
                }

                printf("%c",str[in[i-1]-'0'][cnt]);
                cnt = -1;
            }
            else cnt++;
        }
        printf("\n");
    }

    return 0;
}