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>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    char ans[][10] = {
        {},
        {'.',',','!','?',' '},
        {'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 n; cin >> n;
    rep(i,n){
        string s(100000,0);
        cin >> s;
        int temp = 0;
        int counter =-1 ;
        for(int k = 0;k<s.size();k++){
            int now = int(s[k]-48);
            if(k == 0){temp = now;counter++;}
            else if(now != 0){
                temp = now;counter++;}
            if(now == 0){
                if(temp  == 9 || temp == 7)
                    counter%=4;
                else if(temp != 1&& temp != 7 && temp!= 9)
                    counter%=3;
                else if(temp == 1)
                    counter %=5;
                cout << ans[temp][counter];
                temp = 0;counter =-1;;
            }
        }
        cout << endl;
    }
    return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号

int main(){
	int T;
	cin>>T;
	string bt[]={
		"",
		".,!? ",
		"abc",
		"def",
		"ghi",
		"jkl",
		"mno",
		"pqrs",
		"tuv",
		"wxyz"
	};
	REP(t,T){
		string str,res="";
		cin>>str;
		int npos=0,cnt=0;
		REP(i,SZ(str)){
			if(str[i]=='0'){
				if(cnt!=0){
					int sz=SZ(bt[npos]);
					res+=bt[npos][(cnt+sz-1)%sz];
				}
				cnt=0;npos=0;
			}else{
				npos=str[i]-'0';
				cnt++;
			}
		}
		cout<<res<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

int main(){

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

	int n;

	cin >> n;

	for(int i=0;i<n;i++){
		string str;
		int count=0;
		cin >> str;

		for(int k=0;k<str.length();k++){
			if(str[k] == str[k+1]){
				count++;
			}else{
				string str2 = table[(str[k]-'0')];
				char word = str2[ count % (str2.length()) ];
				if(word != '#'){ cout << word; }
				count=0;
			}
		}

		cout << endl;
	}


}

C++: #include <cstdio>

int main(){
  int N,p,g,a[9]={};
  int i,o;
  char v[76];
  scanf("%d",&N);
  for(i=1;i<=N+1;i++){
    p=0;
     while(1){
      p++;
      scanf("%c",&v[p]);
      if(v[p]=='\n') break;
      if(v[p]=='1') a[0]++;
      if(v[p]=='2') a[1]++;
      if(v[p]=='3') a[2]++;
      if(v[p]=='4') a[3]++;
      if(v[p]=='5') a[4]++;
      if(v[p]=='6') a[5]++;
      if(v[p]=='7') a[6]++;
      if(v[p]=='8') a[7]++;
      if(v[p]=='9') a[8]++;
      if(v[p]=='0') {
	if(v[p-1]=='1') {
	  if(a[0]%5==4) printf("?");
	  if(a[0]%5==1) printf(".");
	  if(a[0]%5==2) printf(",");
	  if(a[0]%5==3) printf("!");
	  if(a[0]%5==0) printf(" ");
	}
	if(v[p-1]=='2'){
	  g=a[1]%3;
	  if(g==0) g=3;
	  printf("%c",96+g);
	}
	if(v[p-1]=='3'){
	  g=a[2]%3;
	  if(g==0) g=3;
	  printf("%c",99+g);
	}
	if(v[p-1]=='4'){
	  g=a[3]%3;
	  if(g==0) g=3;
	  printf("%c",102+g);
	}
	if(v[p-1]=='5'){
	  g=a[4]%3;
	  if(g==0) g=3;
	  printf("%c",105+g);
	}
	if(v[p-1]=='6'){
	  g=a[5]%4;
	  if(g==0) g=4;
	  printf("%c",108+g);
	}
	if(v[p-1]=='7'){
	  g=a[6]%3;
	  if(g==0) g=3;
	  printf("%c",111+g);
	}
	if(v[p-1]=='8'){
	  g=a[7]%3;
	  if(g==0) g=3;
	  printf("%c",115+g);
	}
	if(v[p-1]=='9'){
	  g=a[8]%4;
	  if(g==0) g=3;
	  printf("%c",118+g);
	}
	for(o=0;o<8;o++){
	  a[o]=0;
	}
      } 
     }
     if(i>=2)   printf("\n");
  }
  return 0;
}