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 str;

    while(cin >> str){
        int times = 0;
        char kind = 0;
        string ret = "";
        str += '0';
        for(int i=0;i<str.size();i++){
            if(str[i] == '0'){
                if(times != 0){
                    times--;
                    if(kind == '1'){
                        times %= 5;
                        if(times == 0){
                            ret += '.';
                        }else if(times == 1){
                            ret += ',';
                        }else if(times == 2){
                            ret += '!';
                        }else if(times == 3){
                            ret += '?';
                        }else{
                            ret += ' ';
                        }
                    }else if(kind == '2'){
                        ret += 'a' + (times%3);
                    }else if(kind == '3'){
                        ret += 'd' + (times%3);
                    }else if(kind == '4'){
                        ret += 'g' + (times%3);
                    }else if(kind == '5'){
                        ret += 'j' + (times%3);
                    }else if(kind == '6'){
                        ret += 'm' + (times%3);
                    }else if(kind == '7'){
                        ret += 'p' + (times%4);
                    }else if(kind == '8'){
                        ret += 't' + (times%3);
                    }else if(kind == '9'){
                        ret += 'w' + (times%4);
                    }
                }
                times = 0;
            }else{
                times++;
                kind = str[i];
            }
        }
        cout << ret << endl;
    }
}

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

int main(){
  string s;
  int N;
  char bot[10][20]={"0",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; 

  int count=0,flag=0;
  while(cin>>N){
    for(int i=0;i<N;i++){
      count=0;
      s.clear();
      cin>>s;
      for(int j=0;j<(int)s.size();j++){
	if(s[j]!='0'&&flag==0){
	  flag=s[j]-'0';
	}else if(flag!=0&&s[j]!='0'){
	  count++;
	}else if(s[j]=='0'&&flag!=0){
	  if(count<0&&count<=strlen(bot[flag]))cout<<bot[flag][count];
	  else{
	    while(count>strlen(bot[flag])-1){
	      count=count-strlen(bot[flag]);
	    }

	    cout<<bot[flag][count];
	  }
	  count=0;
	  flag=0;
	}
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>

#define rep(i,n) for(unsigned int i=0; i<n; i++)

void solve(void){

	int m;					//文字列の行数
	std::string sl;		//文字列格納用ストリング型変数

	char c[10][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'},
	};

	std::cin >> m;
	while(m--){

		int t = 0;

		std::cin >> sl;

		rep(i,sl.size()-1){
			if(sl[i] == sl[i+1]){
				t++;
			}else{
				if(sl[i]=='7' || sl[i]=='8'){
					t %= 4;
				}
				else if(sl[i]=='1'){
					t %= 5;
				}else{
					t %= 3;
				}
				if(sl[i] != '0'){
					std::cout << c[sl[i]-'0'][t];
				}
				t = 0;
			}
		}
		std::cout << std::endl;
	}
}

int main(void){

	solve();

	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define all(c) (c).begin(), (c).end()

using namespace std;
template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }


int main() {
	int T;
	int num=0,back_number;
	int index_tok=-1;
	int len_tokens[10] = {0,5,3,3,3,3,3,4,3,4};
	int tokens[10][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','#'}
	};

	cin >> T;
	string a_str;
	rep(t,T) {
		cin >> a_str;
		back_number = 0;
		rep(i,a_str.size()) 
		{
			num = a_str[i] - '0';
			if (num == 0) {
				if (back_number != 0) {
					char a_char = tokens[back_number][index_tok];
					cout << a_char;
					index_tok = -1; //Enterしたら、一番先頭へ
				}
			}
			else {
				index_tok = (index_tok+1) % len_tokens[num];
			}
			back_number=num;
		}
		cout << endl;
	}

	return 0;
}

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

int table_r[10]={0,5,3,3,3,3,3,4,3,4};
char t[10][5] = {{0,0,0,0,0},{'.', ',', '!', '?', ' '},};

int main(){
    char abc='a';
    for(int i=2; i<=9; i++){
        for(int j=0; j<table_r[i]; j++){
            t[i][j]=abc++;
        }
    }

    int n;
    cin >> n;
    char buf[1025];
    for(int i=0; i<n; i++){
        cin >> buf;
        for(int j=0; buf[j]!=0; j++){
            char tmp = buf[j];
            if(tmp=='0') continue;
            int ct;
            for(ct=0; buf[j+ct]!=0; ct++){
                if(buf[j+ct]=='0'){
                    int k = tmp-'0';
                    cout << t[k][(ct-1)%table_r[k]];
                    j+=ct;
                    break;
                }
            }
        }
        cout << endl;
    }
            
    return 0;
}