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<vector>
using namespace std;
vector<pair<int,int> > vpii(80);
string num;
void print(int s,int m,int f){
  switch(f-48){
  case 1:switch(s){
    case 1:cout<<'.';break; case 2:cout<<',';break; case 3:cout<<'!';break;case 4:cout<<'?';break; case 5:cout<<" ";break;}break;
  case 2:switch(s){
    case 1:cout<<'a';break; case 2:cout<<'b';break; case 3:cout<<'c';break;}break;
  case 3:switch(s){
    case 1:cout<<'d';break;case 2:cout<<'e';break;case 3:cout<<'f';break;}break;
  case 4:switch(s){
    case 1:cout<<'g';break;case 2:cout<<'h';break;case 3:cout<<'i';break;} break;
  case 5:switch(s){
    case 1:cout<<'j';break;case 2:cout<<'k';break;case 3:cout<<'l';break;} break;
  case 6:switch(s){
    case 1:cout<<'m';break;case 2:cout<<'n';break;case 3:cout<<'o';break;} break;
  case 7:switch(s){
    case 1:cout<<'p';break;case 2:cout<<'q';break;case 3:cout<<'r';break;case 4:cout<<'s';break;} break;
  case 8:switch(s){
    case 1:cout<<'t';break;case 2:cout<<'u';break;case 3:cout<<'v';break;}break; 
  case 9:switch(s){
    case 1:cout<<'w';break;case 2:cout<<'x';break;case 3:cout<<'y';break;case 4:cout<<'z';break;}break;
  default :break; 
  }
}
void dfs(int m,int d,int w,char f){
  if(w==d){
    print(d,m,f);
    return;
  }
  dfs(m,d,w+1,f);
  return;
}
int main(){
  int k=0,l=0,n;
  cin >> n;
  for(int q=0;q<n;q++){
    l=0;
    cin >> num;
    int a;
    for(int i=0;i<num.size();i++){
      if(i==0)
	a=num[0];
      k++;
      if(i!=0&&num[i]=='0' &&num[i-1]=='0'){
	k=0;
	continue;
      }
      if(num[i]!='0')
	a=num[i];
      if(num[i]=='0'){
	vpii[l]=make_pair(a,k-1);
	l++;
	k=0;
      }
    }
    for(int j=0;j<l;j++){
      int w=0;
      dfs(j,vpii[j].second,w,vpii[j].first);
    }
    cout<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
	char mo[10][6]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	char buf[1025];
	int le[10]={0,5,3,3,3,3,3,4,3,4};
	int i,j,wk,x,px,py,n,len;
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		scanf("%s",buf);
		len=strlen(buf);
		py=0;	px=-1;
		for(j=0;j<len;j++)	{
			x=buf[j]-'0';
			if(x==0)	{
				if(py!=0)	{
					printf("%c",mo[py][px]);
					py=0;	px=-1;
				}
			}
			else {
				py=x;
				px++;
				px=px%le[py];
			}
//			printf("py=%d px=%d\n",py,px);
		}
		printf("\n");
	}
		
	return 0;
}

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

int main(){

  string s1 = ".,!? ";
  string s2 = "abc";
  string s3 = "def";
  string s4 = "ghi";
  string s5 = "jkl";
  string s6 = "mno";
  string s7 = "pqrs";
  string s8 = "tuv";
  string s9 = "wxyz";
  string num;
  int n;
  cin >> n;
  while(n--){
    cin >> num;
    string ans = "";
    int len = num.size();
    int t1, t2, t3, t4, t5, t6 ,t7, t8, t9;
    t1 = t2 = t3 = t4 = t5 = t6 = t7 = t8 = t9 = 0;
    for(int i = 0; i < len; i++){
      if(num[i] == '0'){
        if(t1 > 0) ans += s1[(t1-1)%5];
        if(t2 > 0) ans += s2[(t2-1)%3];
        if(t3 > 0) ans += s3[(t3-1)%3];
        if(t4 > 0) ans += s4[(t4-1)%3];
        if(t5 > 0) ans += s5[(t5-1)%3];
        if(t6 > 0) ans += s6[(t6-1)%3];
        if(t7 > 0) ans += s7[(t7-1)%4];
        if(t8 > 0) ans += s8[(t8-1)%3];
        if(t9 > 0) ans += s9[(t9-1)%4];
        t1 = t2 = t3 = t4 = t5 = t6 = t7 = t8 = t9 = 0;
      }else{
        if(num[i] == '1') t1++;
        if(num[i] == '2') t2++;
        if(num[i] == '3') t3++;
        if(num[i] == '4') t4++;
        if(num[i] == '5') t5++;
        if(num[i] == '6') t6++;
        if(num[i] == '7') t7++;
        if(num[i] == '8') t8++;
        if(num[i] == '9') t9++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<char, int> P;
vector<P> v;

char N2C(char num, int cnt){
	if(num == '1'){
		if(cnt % 4 == 1) return ' ';
		else if(cnt % 4 == 2) return ',';
		else if(cnt % 4 == 3) return '!';
		else if(cnt % 4 == 0) return '?';
	}
	else if(num == '2'){
		if(cnt % 3 == 1) return 'a';
		else if(cnt % 3 == 2) return 'b';
		else if(cnt % 3 == 0) return 'c';
	}
	else if(num == '3'){
		if(cnt % 3 == 1) return 'd';
		else if(cnt % 3 == 2) return 'e';
		else if(cnt % 3 == 0) return 'f';
	}
	else if(num == '4'){
		if(cnt % 3 == 1) return 'g';
		else if(cnt % 3 == 2) return 'h';
		else if(cnt % 3 == 0) return 'i';
	}
	else if(num == '5'){
		if(cnt % 3 == 1) return 'j';
		else if(cnt % 3 == 2) return 'k';
		else if(cnt % 3 == 0) return 'l';
	}
	else if(num == '6'){
		if(cnt % 3 == 1) return 'm';
		else if(cnt % 3 == 2) return 'n';
		else if(cnt % 3 == 0) return 'o';
	}
	else if(num == '7'){
		if(cnt % 4 == 1) return 'p';
		else if(cnt % 4 == 2) return 'q';
		else if(cnt % 4 == 3) return 'r';
		else if(cnt % 4 == 0) return 's';
	}
	else if(num == '8'){
		if(cnt % 3 == 1) return 't';
		else if(cnt % 3 == 2) return 'u';
		else if(cnt % 3 == 0) return 'v';
	}
	else if(num == '9'){
		if(cnt % 4 == 1) return 'w';
		else if(cnt % 4 == 2) return 'x';
		else if(cnt % 4 == 3) return 'y';
		else if(cnt % 4 == 0) return 'z';
	}
	else return 'A';
}

int main(){
	int n;
	cin >> n;
for(int i=0; i<n; i++){	
	
	string s;
	cin >> s;
	int len = s.size();
	
	int head = 0;
	for(int i=0; i < len; i++){
		if(s[i] == '0') head++;
		else break;
	}
	
	
	int body = -1;
	for(int i=head; i<len; i++){
		body++;
		if(s[i] == '0'){
			if(s[i-1] != '0'){
				v.push_back(P(s[i-1], body));
			}
			body = -1;
		}
	}
	
	for(int i=0; i<(int)v.size(); i++){
		cout << N2C(v[i].first, v[i].second);
	}
	cout << endl;
	
	v.clear();
	//debug
	/*
	for(int i=0; i<(int)v.size(); i++){
		cout << v[i].first << " " << v[i].second << endl;
	}
	*/
	
}//end	
	
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		
		string key[]={".,!?, ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	}
	return 0;
}