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(){
	string a,b;
	while (cin>>a){
		if(a=="0") break;
		int la=a.size();
		int c=0;
		for(int i=0;i<la;i++){
			if(a[i]=='0'){
				if(b=="1"){
					c=c%5;
					if(c==1) cout<<".";
					if(c==2) cout<<",";
					if(c==3) cout<<"!";
					if(c==4) cout<<"?";
					if(c==0) cout<<" "; 
				}
				if(b=="2"){
					c=c%3;
					if(c==1) cout<<"a";
					if(c==2) cout<<"b";
					if(c==0) cout<<"c";
				}
				if(b=="3"){
					c=c%3;
					if(c==1) cout<<"d";
					if(c==2) cout<<"e";
					if(c==0) cout<<"f";
				}
				if(b=="4"){
					c=c%3;
					if(c==1) cout<<"g";
					if(c==2) cout<<"h";
					if(c==0) cout<<"i";
				}
				if(b=="5"){
					c=c%3;
					if(c==1) cout<<"j";
					if(c==2) cout<<"k";
					if(c==0) cout<<"l";
				}
				if(b=="6"){
					c=c%3;
					if(c==1) cout<<"m";
					if(c==2) cout<<"n";
					if(c==0) cout<<"o";
				}
				if(b=="7"){
					c=c%4;
					if(c==1) cout<<"p";
					if(c==2) cout<<"q";
					if(c==3) cout<<"r";
					if(c==0) cout<<"s";
				}
				if(b=="8"){
					c=c%3;
					if(c==1) cout<<"t";
					if(c==2) cout<<"u";
					if(c==0) cout<<"v";
				}
				if(b=="9"){
					c=c%4;
					if(c==1) cout<<"w";
					if(c==2) cout<<"x";
					if(c==3) cout<<"y";
					if(c==0) cout<<"z";
				}
				c=0;
				b="0";
			}
			else{
				b=a[i];
				c++;
			}
		}
		cout<<endl;
	}
    return 0;
}

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

/*

    1: . , ! ? (スペース)
    2: a b c
    3: d e f
    4: g h i
    5: j k l
    6: m n o
    7: p q r s
    8: t u v
    9: w x y z
    0: 確定ボタン 
*/

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

string conv(string str) {
  string res = "";
  char c = 'X';
  int num = 0;
  for (int i = 0; i < str.size(); ++i) {
    if (str[i] == '0') {
      if (num > 0) {
	int bu = c - '0';
	int ord = (num - 1) % button[bu].size();
	char add = button[bu][ord];
	res += add;
	num = 0;
      }
    }
    else {
      c = str[i];
      ++num;
    }
  }
  return res;
}

int main() {
  int n; cin >> n;
  for (int i = 0; i < n; ++i) {
    string str; cin >> str;
    cout << conv(str) << endl;
  }
}

C++: #include "bits/stdc++.h"

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    int n;cin>>n;
    vector<string> v;
    v.push_back("");v.push_back(".,!? ");v.push_back("abc");
    v.push_back("def");v.push_back("ghi");v.push_back("jkl");
    v.push_back("mno");v.push_back("pqrs");v.push_back("tuv");
    v.push_back("wxyz");
    for(int i=0;i<n;i++){
        string s;cin>>s;
        s+='0';
        string res="";
        int cnt=0,idx=0;
        for(int j=0;j<(int)s.length();j++){
            if(s[j]-'0' ==0){
                if(cnt==0) continue;
                res+=v[idx][(cnt-1)%(v[idx].length())];
                cnt=0;
            }
            else{
                idx=s[j]-'0';
                cnt++;
            }
        }
        cout<<res<<endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){   
  char m[9][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 a,count=0,c[100],d;
  char b[100][1024];
  cin>>a;
  for(int i=0;i<a;i++){
    scanf("%s",b[i]);
    c[i]=strlen(b[i]);
    for(int j=0;j<c[i];j++){

      if(b[i][j]!='0'){
	count++;
	d=(int)(b[i][j])-48;
      }
      else{
	if(b[i][j-1]!=0){
	  if(d==1)
	    if(count%5==0)
	      cout<<m[d-1][4];
	    else 
	      cout<<m[d-1][count%5-1];
	  
	  else if(d==7 || d==9)
	    if(count%4==0)
	      cout<<m[d-1][3];
	    else
	      cout<<m[d-1][count%4-1];
	  
	  else
	    if(count%3==0)
	      cout<<m[d-1][2];
	    else
	      cout<<m[d-1][count%3-1];
	  count=0;
	}
      }
    }
    cout<<endl;
  }
  return 0;
}

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

char bt[9][8] = {
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};

int main(){
    int N;
    char mes[80];
    for(scanf("%d", &N); N--;){
        scanf(" %s", mes);
        int len = strlen(mes);
        int prv = 0, count = 0;
        for(int i = 0; i < len; i++){
            if(mes[i] == '0'){
                if(prv > 0){
                    --prv;
                    printf("%c", bt[prv][--count % strlen(bt[prv])]);
                }
                count = 0;
            }else{
                count++;
            }
            prv = mes[i] - '0';
        }
        if(prv > 0){
            --prv;
            printf("%c", bt[prv][count % strlen(bt[prv])]);
        }
        puts("");
    }
    return 0;
}