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 <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const string L[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
int main(void){
    int n; cin >> n;
    for(string in; n-- && cin >> in; cout << endl){
        int cur = 0, cnt = 0;
        rep(i, in.size()){
            if(in.at(i) - '0' == cur) cnt++;
            else{
                if(in.at(i) == '0'){
                    cout << L[cur].at((cnt + L[cur].size()) % L[cur].size());
                }
                cur = in.at(i) - '0';
                cnt = 0;
            }
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
vector<vector<char> > button(10);


int main(void){
  char c = 'a';
  button[1].push_back('.');
  button[1].push_back(',');
  button[1].push_back('!');
  button[1].push_back('?');
  button[1].push_back(' ');
  for(int i=2; i <= 9; i++){
    if(i == 7 || i == 9){
      for(int j=0; j < 4; j++){
	button[i].push_back(c);
	c++;
      }
    }else{
      for(int j=0; j < 3; j++){
	button[i].push_back(c);
	c++;
      }
    }
  }


  int n;
  string s;
  cin >> n;
  while(n--){
    cin >> s;
    int cnt=0;
    string mes;
    for(int i=0; i < s.length(); i++){
      if(s[i] == '0'){
	if(i == 0)      continue;
	if(s[i-1] == '0') continue;
	mes.append(1, button[s[i-1]-'0'][(cnt-1)%button[s[i-1]-'0'].size()]);
	cnt = 0;
      }else{
	cnt++;
      }
    }
    cout << mes << endl;
  }
  return 0;
}

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

using namespace std;

const char keibutton[10][5]={{'\0','\0','\0','\0','\0'},
							 {'.',',','!','?',' '}, //1
						     {'a','b','c'},     //2
						     {'d','e','f'},     //3
						     {'g','h','i'},     //4
						     {'j','k','l'},     //5
						     {'m','n','o'},     //6
						     {'p','q','r','s'}, //7
						     {'t','u','v'},     //8
						     {'w','x','y','z'}};//9


int main(){
	int n,cnt,outcnt,inpcnt;
	char str[1025],outputStr[1025];
	
	cin>>n;
	
	for(int z=0;z<n;z++){
		
		fill(str,str+1025,'\0');
		fill(outputStr,outputStr+1025,'\0');
		cnt=-1;
		inpcnt=0;
		outcnt=0;
		
		cin>>str;
		
		while(true){
			if(str[inpcnt]=='\0'){
				break;
			}
			inpcnt++;
		}
		
		for(int i=0;i<inpcnt;i++){
			if(str[i]=='0'){
				if(i>0 && str[i-1]!='0'){
					outputStr[outcnt]=keibutton[str[i-1]-'0'][cnt];
					outcnt++;
				}
				cnt=-1;
			}
			else if(str[i]=='1'){
				if(cnt>=5){
					cnt=0;
				}
				else{
					cnt++;
				}
			}
			else if(str[i]=='7' || str[i]=='9'){
				if(cnt>=3){
					cnt=0;
				}
				else{
					cnt++;
				}
			}
			else{
				if(cnt>=2){
					cnt=0;
				}
				else{
					cnt++;
				}
			}
		}
		cout<<outputStr<<endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vector<vector<T>> read(int n, int m)
{
	vector<vector<T>> v;
	REP(i,n) { v.push_back(read<T>(m)); }
	return v;
}

template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }
template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

void solve();
int main() { solve(); return 0; }

/// template end ///

void solve()
{
	READ(int, datasets);
	const string tbl[] = { ".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" };
	REP(dataset, datasets)
	{
		READ(string, input);
		string ret;
		for (auto it = input.begin(); it != input.end(); it++)
		{
			int c = *it - '0';
			if (c != 0)
			{
				const string &t = tbl[c - 1];
				auto f = find(it + 1, input.end(), '0');
				ret.push_back(t[(f - it - 1) % t.length()]);
				it = f;
			}
		}
		write(ret);
	}
}

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

using namespace std;

int main()
{
  vector<string> keitai(9);
  keitai[0] = ".,!? ";  keitai[1] = "abc";  keitai[2] = "def";  keitai[3] = "ghi";
  keitai[4] = "jkl";  keitai[5] = "mno";  keitai[6] = "pqrs"; keitai[7] = "tuv";  keitai[8] = "wxyz";

  int N;
  cin>>N;

  for(int i = 0;i < N;++i){
    string input,output;
    cin>>input;

    int word,t = 0;
    for(int j = 0;j < input.size();++j){
      if(input[j] == '0' && word != 0){
        int num = t % keitai[word - 1].size();
        if(num == 0){
          num = keitai[word - 1].size();
        }
        output = output + keitai[word - 1][num - 1];
        t = 0;
        word = 0;
      }
      else{
        word = input[j] - '0';
        if(word != 0){
          ++t;
        }
      }
    }
    cout<<output<<endl;
  }

  return 0;
}

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

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

int main(){
	
	int n ;
	string s ;
	cin >> n ;
	for( int i=0 ; i<n ; i++ ){
		cin >> s ;
		for( int j=0 ; j<s.size() ; j++ ){
			int cnt = 0 , p = 3 ;
			char a = s[j] ;
			if( a == '0' ) continue ;
			if( a == '1' ) p = 5 ;
			if( a == '7' || a == '9' ) p = 4 ;
			for( j+=1 ; j<s.size() ; j++ ){
				if( s[j] == a ) cnt++ ;
				if( s[j] == '0' ) break ;
			}
			cout << table[a-'0'-1][cnt%p] ;
		}
		cout << endl ;
	}
	
return 0 ;
}