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>

using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string msg;
        string output = "";
        int count = 0;
        char buf = '\0';

        cin >> msg;

        for (int j = 0; j < (int)msg.size(); j++) {
            char c = msg[j];

            if (c == '0' && j != 0) {
                if (buf == '1') {
                    if (count % 5 == 1)
                        output += ".";
                    else if (count % 5 == 2)
                        output += ",";
                    else if (count % 5 == 3)
                        output += "!";
                    else if (count % 5 == 4)
                        output += "?";
                    else if (count % 5 == 0)
                        output += " ";
                } else if (buf == '2') {
                    if (count % 3 == 1)
                        output += "a";
                    else if (count % 3 == 2)
                        output += "b";
                    else if (count % 3 == 0)
                        output += "c";
                } else if (buf == '3') {
                    if (count % 3 == 1)
                        output += 'd';
                    else if (count % 3 == 2)
                        output += 'e';
                    else if (count % 3 == 0)
                        output += 'f';
                } else if (buf == '4') {
                    if (count % 3 == 1)
                        output += 'g';
                    else if (count % 3 == 2)
                        output += 'h';
                    else if (count % 3 == 0)
                        output += 'i';
                } else if (buf == '5') {
                    if (count % 3 == 1)
                        output += 'j';
                    else if (count % 3 == 2)
                        output += 'k';
                    else if (count % 3 == 0)
                        output += 'l';
                } else if (buf == '6') {
                    if (count % 3 == 1)
                        output += 'm';
                    else if (count % 3 == 2)
                        output += 'n';
                    else if (count % 3 == 0)
                        output += 'o';
                } else if (buf == '7') {
                    if (count % 4 == 1)
                        output += 'p';
                    else if (count % 4 == 2)
                        output += 'q';
                    else if (count % 4 == 3)
                        output += 'r';
                    else if (count % 4 == 0)
                        output += 's';
                } else if (buf == '8') {
                    if (count % 3 == 1)
                        output += 't';
                    else if (count % 3 == 2)
                        output += 'u';
                    else if (count % 3 == 0)
                        output += 'v';
                } else if (buf == '9') {
                    if (count % 4 == 1)
                        output += 'w';
                    else if (count % 4 == 2)
                        output += 'x';
                    else if (count % 4 == 3)
                        output += 'y';
                    else if (count % 4 == 0)
                        output += 'z';
                }
                count = 0;
                buf = '\0';
            } else {
                count++;
                buf = msg[j];
            }
        }
        cout << output << endl;
    }

    return 0;
}

C++: a

C++: #include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>

#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rep_to(a,i,x) for(int i=a;i<x;i++)

using namespace std;

int main()
{
	int n;
	cin >> n;

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


	rep(i,n)
	{
		string str;
		int keep=0;
		int num[100]={};

		cin >> str;

		rep(j,str.length())
		{
			if(str[j]=='0')
			{
				if( keep-1==0 && (num[keep]-1)%5==4 )cout<<" ";
				else if(num[keep]>=1)cout << set[keep-1][(num[keep]-1)%strlen(set[keep-1])];
				num[keep]=0;
				/*cout << num[keep] <<endl;*/
			}
			else 
			{
				keep=str[j] - '0';
				num[keep]++;
			}
			str[j]=0;
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string input;
		char first=input[0];
		int count=1;
		
		cin>>input;
		for(int j=1;j<input.size();j++){
			if(first==input[j])count++;
			if(input[j]=='0'){
				if(input[j+1]=='0')continue;
				switch(first){
					case '1':
						switch(count%5){
							case 1:cout<<".";break;
							case 2:cout<<",";break;
							case 3:cout<<"!";break;
							case 4:cout<<"?";break;
							case 0:cout<<" ";break;
						}break;
					case '2':
						switch(count%3){
							case 1:cout<<"a";break;
							case 2:cout<<"b";break;
							case 0:cout<<"c";break;
						}break;
					case '3':
						switch(count%3){
							case 1:cout<<"d";break;
							case 2:cout<<"e";break;
							case 0:cout<<"f";break;
						}break;
					case '4':
						switch(count%3){
							case 1:cout<<"g";break;
							case 2:cout<<"h";break;
							case 0:cout<<"i";break;
						}break;
					case '5':
						switch(count%3){
							case 1:cout<<"j";break;
							case 2:cout<<"k";break;
							case 0:cout<<"l";break;
						}break;
					case '6':
						switch(count%3){
							case 1:cout<<"m";break;
							case 2:cout<<"n";break;
							case 0:cout<<"o";break;
						}break;
					case '7':
						switch(count%4){
							case 1:cout<<"p";break;
							case 2:cout<<"q";break;
							case 3:cout<<"r";break;
							case 0:cout<<"s";break;
						}break;
					case '8':
						switch(count%3){
							case 1:cout<<"t";break;
							case 2:cout<<"u";break;
							case 0:cout<<"v";break;
						}break;
					case '9':
						switch(count%4){
							case 1:cout<<"w";break;
							case 2:cout<<"x";break;
							case 3:cout<<"y";break;
							case 0:cout<<"z";break;
						}break;
				}
				first=input[j+1];
				count=0;
			}	
		}
		
			cout<<endl;	
	}
}