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;

int main(void){
  int n, i, cnt;
  string str, ans;
  char init;
  vector<string> mp{"", ".,!? ","abc","def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  cin >> n;
  while(n--){
    cin >> str;
    ans = "";
    i = 0;
    while(i < str.length()){
      while(str[i] == '0'){
        i++;
      }
      if(i >= str.length()){
        break;
      }
      init = str[i];
      cnt = 0;
      while(i < str.length() and str[i] == init){
        i++;
        cnt++;
      }
      ans += mp[init - '0'][(cnt - 1) % mp[init - '0'].length()];
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string str,one=".,!? ",ans;
		cin>>str;
		for(int j=0,co=0,num=0;j<=str.size();j++){
			if(num==str[j]-'0')co++;
			else{
				if(num==1)ans+=one[co%5];
				else if(num==7)ans+=co%4+'p';
				else if(num==8)ans+=co%3+'t';
				else if(num==9)ans+=co%4+'w';
				else if(num>1)ans+=co%3+'a'+3*(num-2);
				co=0;
				num=str[j]-'0';
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <stdio.h>
#include <string.h>

// int zero_count(char str[]) {
//   int a;
//   int cnt = 0;
//   a = strlen(str);
//   for (int i = 0; i < a; i++) {
// 	if (str[i] == '0') {
// 	  ctr++;
// 	}
//   }
//   return ctr;
// }

int main(void) {
  int n;
  // int zero_num = 0;
  int i, j, k;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
	char str[10000] = {0};
	char ans[10000] = {0};
	scanf("%s", str);
	int len;
	// char c;
	len = strlen(str);
	j = 0;
	k = 0;
	int /* zero[100] = {0},*/ one[100] = {0}, two[100] = {0}, three[100] = {0}, four[100] = {0};
	int five[100] = {0}, six[100] = {0}, seven[100] = {0}, eight[100] = {0}, nine[100] = {0};
	int cnt = 0;
	
	while(1) {
	  switch (str[j]) {
	  case '0':
		///////////////////////////////////////////////////////////////////////////////
		if (one[k] != 0) {
		  cnt = one[k] % 5;
		  switch(cnt) {
		  case 1:
			ans[k] = '.';
			break;
		  case 2:
			ans[k] = ',';
			  break;
		  case 3:
			ans[k] = '!';
			break;
		  case 4:
			ans[k] = '?';
			break;
		  case 0:
			ans[k] = ' ';
			break;
		  }
		  k++;
		}
		else if (two[k] != 0) {
		  cnt = two[k] % 3;
		  switch(cnt) {
		  case 1:
			ans[k] = 'a';
			break;
		  case 2:
			ans[k] = 'b';
			  break;
		  case 0:
			ans[k] = 'c';
			break;
		  }
		  k++;
		}
		else if (three[k] != 0) {
		  cnt = three[k] % 3;
		  switch(cnt) {
		  case 1:
			ans[k] = 'd';
			break;
		  case 2:
			ans[k] = 'e';
			  break;
		  case 0:
			ans[k] = 'f';
			break;
		  }
		  k++;
		}
		else if (four[k] != 0) {
		  cnt = four[k] % 3;
		  switch(cnt) {
		  case 1:
			ans[k] = 'g';
			break;
		  case 2:
			ans[k] = 'h';
			  break;
		  case 0:
			ans[k] = 'i';
			break;
		  }
		  k++;
		}
		else if (five[k] != 0) {
		  cnt = five[k] % 3;
		  switch(cnt) {
		  case 1:
			ans[k] = 'j';
			break;
		  case 2:
			ans[k] = 'k';
			  break;
		  case 0:
			ans[k] = 'l';
			break;
		  }
		  k++;
		}
		else if (six[k] != 0) {
		  cnt = six[k] % 3;
		  switch(cnt) {
		  case 1:
			ans[k] = 'm';
			break;
		  case 2:
			ans[k] = 'n';
			  break;
		  case 0:
			ans[k] = 'o';
			break;
		  }
		  k++;
		}
		else if (seven[k] != 0) {
		  cnt = seven[k] % 4;
		  switch(cnt) {
		  case 1:
			ans[k] = 'p';
			break;
		  case 2:
			ans[k] = 'q';
			break;
		  case 3:
			ans[k] = 'r';
			break;
		  case 0:
			ans[k] = 's';
			break;
		  }
		  k++;
		}

		else if (eight[k] != 0) {
		  cnt = eight[k] % 3;
		  switch(cnt) {
		  case 1:
			ans[k] = 't';
			break;
		  case 2:
			ans[k] = 'u';
			break;
		  case 0:
			ans[k] = 'v';
			break;
		  }
		  k++;
		}
		else if (nine[k] != 0) {
		  cnt = nine[k] % 4;
		  switch(cnt) {
		  case 1:
			ans[k] = 'w';
			break;
		  case 2:
			ans[k] = 'x';
			break;
		  case 3:
			ans[k] = 'y';
			break;
		  case 0:
			ans[k] = 'z';
			break;
		  }
		  k++;
		}
		////////////////////////////////////////////////////////////
		break;
	  case '1':
		one[k]++;
		break;
	  case '2':
		two[k]++;
		break;
	  case '3':
		three[k]++;
		break;
	  case '4':
		four[k]++;
		break;
	  case '5':
		five[k]++;
		break;
	  case '6':
		six[k]++;
		break;
	  case '7':
		seven[k]++;
		break;
	  case '8':
		eight[k]++;
		break;
	  case '9':
		nine[k]++;
		break;
	  }
	  j++;
	  if (len == j) break;
	}
   
	printf("%s\n", ans);
  }



		
   
  return 0;
}

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[5000]={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+2)%3;
	now = 'a'+out;
	cout << now;
      }else if(num[c]==3){
	while(num[c]==3){
	  k++;
	  c++;
	}
	out=(k+2)%3;
	now = 'd'+out;
	cout << now;
      }else if(num[c]==4){
	while(num[c]==4){
	  k++;
	  c++;
	}
	out=(k+2)%3;
	now = 'g'+out;
	cout << now;
      }else if(num[c]==5){
	while(num[c]==5){
	  k++;
	  c++;
	}
	out=(k+2)%3;
	now = 'j'+out;
	cout << now;
      }else if(num[c]==6){
	while(num[c]==6){
	  k++;
	  c++;
	}
	out=(k+2)%3;
	now = 'm'+out;
	cout << now ;
      }else if(num[c]==7){
	while(num[c]==7){
	  k++;
	  c++;
	}
	out=(k+3)%4;
	now = 'p'+out;
	cout << now;
      } else if(num[c]==8){
	while(num[c]==8){
	  k++;
	  c++;
	}
	out=(k+2)%3;
	now = 't'+out;
	cout << now;
      }else if(num[c]==9){
	while(num[c]==9){
	  k++;
	  c++;
	}
	out=(k+3)%4;
	now = 'w'+out;
	cout << now;
      }
    }
      cout << endl;
  }}