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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) begin(s),end(s)
#define VIEW(dat) for(auto v : dat){cout<<v<<endl;}
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))


const int INF=1<<24;

using namespace std;

string valOf(int n){ stringstream ss;ss<<n;return ss.str();}
int    valOf(string s){return atoi(s.c_str());}
int    valOf(char s){return (unsigned int)(s - '0');}

string deco(int id,int n){
	switch(id){
		case 1:
		switch(n){
			case 0:	return ".";
			case 1:	return ",";
			case 2:	return "!";
			case 3:	return "?";
			case 4:	return " ";	
		}break;
		case 2:
		switch(n){
			case 0:	return "a";
			case 1:	return "b";
			case 2:	return "c";
		}break;	
		case 3:
		switch(n){
			case 0:	return "d";
			case 1:	return "e";
			case 2:	return "f";
		}break;	
		case 4:
		switch(n){
			case 0:	return "g";
			case 1:	return "h";
			case 2:	return "i";
		}break;	
		case 5:
		switch(n){
			case 0:	return "j";
			case 1:	return "k";
			case 2:	return "l";
		}break;	
		case 6:
		switch(n){
			case 0:	return "m";
			case 1:	return "n";
			case 2:	return "o";
		}break;	
		case 7:
		switch(n){
			case 0:	return "p";
			case 1:	return "q";
			case 2:	return "r";
			case 3:	return "s";
		}break;		
		case 8:
		switch(n){
			case 0:	return "t";
			case 1:	return "u";
			case 2:	return "v";
		}break;	
		case 9:
		switch(n){
			case 0:	return "w";
			case 1:	return "x";
			case 2:	return "y";
			case 3:	return "z";
		}break;	
	}
	return "";
}



string solve(string s){
	int nn=-1;
	string rls="";
	vector<int> num(10);
	rep(i,9){
		num[i]=0;
	}
	rep(i,s.size()){
		if(!valOf(s[i])){
			rls+=deco(nn,num[nn]);
			rep(i,9){
				num[i]=0;
			}
			nn=-1;
		}
		switch(valOf(s[i])){
			case 1:
				if(nn==1){
			    	num[nn]++;
			    }nn=1;
				if(num[nn]>4){
					num[nn]=0;
				}
				break;
			case 2:
			   if(nn==2){
			    	num[nn]++;
			    } nn=2;
				if(num[nn]>2){
					num[nn]=0;
				}
				break;
			case 3:
				if(nn==3){
			    	num[nn]++;
			    }nn=3;
				if(num[nn]>2){
					num[nn]=0;
				}
				break;
			case 4:
				if(nn==4){
			    	num[nn]++;
			    }nn=4;
				if(num[nn]>2){
					num[nn]=0;
				}
				break;
			case 5:
				if(nn==5){
			    	num[nn]++;
			    }nn=5;
				if(num[nn]>2){
					num[nn]=0;
				}
				break;
			case 6:
				if(nn==6){
			    	num[nn]++;
			    }nn=6;
				if(num[nn]>2){
					num[nn]=0;
				}
				break;
			case 7:
				if(nn==7){
			    	num[nn]++;
			    }nn=7;
				if(num[nn]>3){
					num[nn]=0;
				}
				break;
			case 8:
				if(nn==8){
			    	num[nn]++;
			    }nn=8;
				if(num[nn]>2){
					num[nn]=0;
				}
				break;
			case 9:
				if(nn==9){
			    	num[nn]++;
			    }nn=9;
				if(num[nn]>3){
					num[nn]=0;
				}
				break;
		}
	}
	return rls;
}
	

int main(){
	
	int  n;
	
	string in;
	
	cin>>n;
	while(n--){
		cin>>in;
		cout<<solve(in)<<endl;
	}
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
#define MAXNUM 1024
using namespace std;
typedef long long ll;

int main(){
  int n; cin >> n;
  string dict[10] = {
    {""},
    {".,!? "},
    {"abc"},
    {"def"},
    {"ghi"},
    {"jkl"},
    {"mno"},
    {"pqrs"},
    {"tuv"},
    {"wxyz"},
  };

  REP(i, n){
    string input;  cin >> input;
    int num = 0, cnt=-1;
    REP(j, input.length()){
      if(input[j] != '0'){
        if(num==0)  num = input[j] - '0';
        cnt++;
        continue;
      }else{
        if(num!=0){
          cnt %= dict[num].length();
          cout << dict[num][cnt];
          cnt = -1;
          num = 0;
        }
      }
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;
vector<char> key[10];

void Init(){
  int index=0;
  key[1].push_back('.');key[1].push_back(',');key[1].push_back('!');key[1].push_back('?');key[1].push_back(' ');
  for(int i=2;i<=9;i++){
    if(i == 7 || i == 9){
      for(int j=0;j<4;j++){
	key[i].push_back((char)('a'+index));
	index++;
      }	
    }else{
      for(int j=0;j<3;j++){
	key[i].push_back((char)('a'+index));
	index++;
      }
    }
  }
  key[0].push_back('_');
  /*
  for(int i=0;i<=9;i++){
    for(int j=0;j<key[i].size();j++){
      cout << key[i][j] << " ";
    }
    cout << endl;
  }
  */
}


int main(){
  Init();
  int T,div,cnt;
  string s;
  char th;
  bool zcnt;
  cin >> T;
  while(T-- > 0){
    cin >> s;
  
    char p = s[0];
    int cnt = 0;
    for(int i=0;i<s.length();i++){
      if(s[i] == '0'){
	//cout << "p = "<< p << ",cnt = " << cnt << endl;
	cnt--;
	int Size = key[p-'0'].size();
	if(p != '0')cout << key[p-'0'][cnt%Size];
	cnt = 0;
	p = s[i+1];
	continue;
      }
      cnt++;
    }cout << endl;
  }
  return 0;
}