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;

        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 << '\n';
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	string a;
	string d[10] = { "",".,!? ","abc","def","ghi","jkl","mno",
		"pqrs","tuv","wxyz" };
	int m;
	cin >> m;
	for (int z = 0; z < m; z++) {
		cin >> a;
		string c = "";
		for (int i = 0; i < a.length();) {
			while (a[i] == '0'&&i < a.length())i++;
			if (i == a.length()) break;
			int j = i;
			while (a[j] == a[i] && i < a.length()) {
				i++;
			}
			int sum = i - j - 1;
			sum %= d[(int)a[j] - '0'].length();
			if (i < a.length() && a[i] == '0')c += d[(int)a[j] - '0'][sum];
		}
		if (c != "") cout << c << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
using namespace std;

int N;
string input, keitai[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
stack<char> st;

int main(void){
  cin >> N;
  while(N--){
    cin >> input;
    for(int i = 0; i < input.size(); i++){
      if(input[i] == '0' && !st.empty()){
        int cnt = 0, b = st.top() - '0';
        while(!st.empty()){
          st.pop(); cnt++;
        }
        cout << keitai[b][(cnt - 1) % keitai[b].size()];
      }else if(input[i] != '0'){
        st.push(input[i]);
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
  int n;
  string str;
  char one[] = {'.',',','!','?',' '};
  int xxx[10] = {0,5,3,3,3,3,3,4,3,4};
  int yyy[10] = {0,0,0,3,6,9,12,15,19,22};
  cin >> n;
  while(n--){
    vector<char> msg;
    vector<int> msg_n;
    cin >> str;
    char curr = str[0];
    int num = 1;
    for(int i=1; i<str.size(); i++){
      if(str[i] == curr)
	num++;
      else{
	if(str[i-1] != '0'){
	  msg.push_back(str[i-1]);
	  msg_n.push_back(num);
	}
	num = 1;
	curr = str[i];
      }
    }
    if(curr != '0'){
      msg.push_back(curr);
      msg_n.push_back(num);
    }
    int pos, pres;
    for(int i=0; i<msg.size(); i++){
      if(msg[i] == '1')
	cout << one[(msg_n[i]+4)%5];
      else{
	pos = msg[i] - '0';
	pres = yyy[pos] + ((msg_n[i]+xxx[pos]-1) % xxx[pos]) + 'a';
	char ttt = pres;
	cout << ttt;
      }
    }
    cout << endl;
  }

  return 0;
}