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 <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  int m;
  cin>>m;
  REP(i,m){
    string str;
    int num[1000]={0};
    char now;
    int out=0;
    char one[5]={'.',',','!','?',' '};
    cin >> str;
    int hoge = str.size();
    REP(i,hoge){
      num[i] = str[i] - '0';
    };
    REP(c,hoge){
      int k=0;
      if(num[c]==1){
	while(num[c]==1){
	  k++;
	  c++;
	}
	out=(k+4)%5;
	cout << one[out];
      }else if(num[c]==2){
	while(num[c]==2){
	  k++;
	  c++;
	}
	out=(k-1)%3;
	now = 'a'+out;
	cout << now;
      }else if(num[c]==3){
	while(num[c]==3){
	  k++;
	  c++;
	}
	out=(k-1)%3;
	now = 'd'+out;
	cout << now;
      }else if(num[c]==4){
	while(num[c]==4){
	  k++;
	  c++;
	}
	out=(k-1)%3;
	now = 'g'+out;
	cout << now;
      }else if(num[c]==5){
	while(num[c]==5){
	  k++;
	  c++;
	}
	out=(k-1)%3;
	now = 'j'+out;
	cout << now;
      }else if(num[c]==6){
	while(num[c]==6){
	  k++;
	  c++;
	}
	out=(k-1)%3;
	now = 'm'+out;
	cout << now ;
      }else if(num[c]==7){
	while(num[c]==7){
	  k++;
	  c++;
	}
	out=(k-1)%4;
	now = 'p'+out;
	cout << now;
      } else if(num[c]==8){
	while(num[c]==8){
	  k++;
	  c++;
	}
	out=(k-1)%3;
	now = 't'+out;
	cout << now;
      }else if(num[c]==9){
	while(num[c]==9){
	  k++;
	  c++;
	}
	out=(k-1)%4;
	now = 'w'+out;
	cout << now;
      }
    }
      cout << endl;
  }}

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(11);
	rep(i,10){
		num[i]=0;
	}
	rep(i,s.size()){
		if(!valOf(s[i])){
			rls+=deco(nn,num[nn]);
			rep(i,10){
				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;
	
	//ifstream cin("in.txt");
	
	cin>>n;
	while(n--){
		cin>>in;
		cout<<solve(in)<<endl;
	}
}