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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
char in[9][5]={
  {'.',',','!','?',' '},
  {'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 in1[9]={5,3,3,3,3,3,4,3,4};
int main(){
  int n;
  cin>>n;
  rep(j,n){
    string s;
    cin>>s;
    int i=0;
    while(i!=s.size()){
      int co=0;
      while(s[i]!='0'){
	co++;
	i++;
      }
      //cout<<co<<endl;
      if(co)cout<<in[s[i-1]-'0'-1][(co-1)%in1[s[i-1]-'0'-1]];
      i++;
    }
    cout<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	char a[9][5]={{'.',',','!','?',' '},{'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,b=0,c=0,d=0;
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;b=d=c=0;
			for(int j=0;j<s.size();j++){
				if(s[j]=='0'&&c>0){
					if(s[j-1]=='1')d=(c-1)%5;
					else if(s[j-1]=='7'||s[j-1]=='9')d=(c-1)%4;
					else d=(c-1)%3;
					cout<<a[(int)(s[j-1]-'0')-1][d];
				c=0;
				}
				else c++;
				}
				cout<<endl;
	}
	return 0;
}

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

int main(){
	
	string k[256];
	k['1']=".,!? ";
	k['2']="abc";
	k['3']="def";
	k['4']="ghi";
	k['5']="jkl";
	k['6']="mno";
	k['7']="pqrs";
	k['8']="tuv";
	k['9']="wxyz";
	k['0']="";
	
	int n;cin>>n;
	while(n--){
		string s;cin>>s;
		for(int i=0;i<s.size();i++){
			if(i==0 && s[i]=='0')continue;
			int t=-1;
			while(s[i]!='0'){
				t++;
				i++;
			}
			if(s[i-1]=='0')continue;
			cout<<k[s[i-1]][t%k[s[i-1]].size()];
		}
		cout<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
#define P pair<int,string>
const P m[10] = {
  P(0,""), P(5,".,!? "), P(3,"abc"), P(3,"def"), P(3,"ghi"),
  P(3,"jkl"), P(3,"mno"), P(4,"pqrs"), P(3, "tuv"), P(4,"wxyz"),
};
int main()
{
  int n;
  cin >> n;
  while(n--){
    string s;
    cin >> s;
    int p,i,j=0;
    for(i=0;i<s.length();i++){
      if(s[i] == '0' && j != 0){
	cout << (m[p].second)[(j-1)%(m[p].first)];
	j = 0;
      }else if(s[i] != '0'){
	p = s[i] - '0';
	j++;
      }
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;


int main(){
	char a1[5] = {'.',',','!','?',' '}; 
	char a2[3] = {'a','b','c'};
	char a3[3] = {'d','e','f'};
	char a4[3] = {'g','h','i'};
	char a5[3] = {'j','k','l'};
	char a6[3] = {'m','n','o'};
	char a7[4] = {'p','q','r','s'};
	char a8[3] = {'t','u','v'};
	char a9[4] = {'w','x','y','z'};
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		string str;
		cin >> str;
		if (cin.eof()) break;
		char num;
		int cnt = 0;	
		for (int i = 0; i < str.size(); i++){	
			cnt++;
			if (str[i] == '0'){
				if (str[i-1] == '1'){ 
					cout << a1[(cnt - 2)%(sizeof(a1))]  ;
				}else if (str[i-1] == '2'){
					cout << a2[(cnt - 2)%(sizeof(a2))]  ;
				}else if (str[i-1] == '3'){
					cout << a3[(cnt - 2)%(sizeof(a3))]  ;
				}else if (str[i-1] == '4'){
					cout << a4[(cnt - 2)%(sizeof(a4))]  ;
				}else if (str[i-1] == '5'){
					cout << a5[(cnt - 2)%(sizeof(a5))]  ;
				}else if (str[i-1] == '6'){
					cout << a6[(cnt - 2)%(sizeof(a6))]  ;
				}else if (str[i-1] == '7'){
					cout << a7[(cnt - 2)%(sizeof(a7))]  ;
				}else if (str[i-1] == '8'){
					cout << a8[(cnt - 2)%(sizeof(a8))]  ;
				}else if (str[i-1] == '9'){
					cout << a9[(cnt - 2)%(sizeof(a9))]  ;
				}
				cnt = 0;
			}
		}
		cout << endl;
	}
	
return 0;
}