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<cstdio>
#include<cstring>
using namespace std;
int main(){
  char m[9][5]={{'.',',','!','?',' '},
		{'a','b','c','1','1'},
		{'d','e','f','1','1'},
		{'g','h','i','1','1'},
		{'j','k','l','1','1'},
		{'m','n','o','1','1'},
		{'p','q','r','s','1'},
		{'t','u','v','1','1'},
		{'w','x','y','z','1'}};

  int a,count=0,c[100],d;
  char b[100][1024];
  cin>>a;
  for(int i=0;i<a;i++){
    scanf("%s",b[i]);
    c[i]=strlen(b[i]);
    for(int j=0;j<c[i];j++){
      if(b[i][j]!='0')count++;
      else
	if(b[i][j-1]!=0){
	  d=(int)(b[i][j-1])-48;

	  if(d==1)
	    if(count%5!=0)
	      cout<<m[d-1][count%5-1];
	    else cout<<m[d-1][4];

	  else if(d==7 || d==9)
	    if(count%4!=0)
	      cout<<m[d-1][count%4-1];
	    else cout<<m[d-1][3];

	  else
	    if(count%3!=0)
	      cout<<m[d-1][count%3-1];
	    else cout<<m[d-1][2]; 
	  count=0;
	}
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
using namespace std;

char KeitaiKey[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;
string input;
stack<int> bt;

void init(){
  while(!bt.empty()) bt.pop();
}

int main(void){
  cin >> N;
  for(int i = 0; i < N; i++){
    init();
    cin >> input;
    for(int j = 0; j < input.size(); j++){
      if(input[j] == '0' && !bt.empty()){
        int nowbt = bt.top()  - 1;
        int size = bt.size();
        if(nowbt == 7 || nowbt == 9){
          if(size > 4) size = size % 4 - 1;
          else size--;
          cout << KeitaiKey[nowbt][size];
        }else if(nowbt == 0){
          if(size > 5) size = size % 5 - 1;
          else size--;
          cout << KeitaiKey[nowbt][size];
        }else{
          if(size > 3) size = size % 3 - 1;
          else size--;
          cout << KeitaiKey[nowbt][size];
        }
        init();
      }else if(input[j] != '0'){
        bt.push(input[j] - '0') ;
      }
    }
    cout << endl;
  }
  return 0;
}

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;
		char ss[40];
			for(int j=0;j<s.size();j++){
				if(s[j]=='0'&&c>0){
					if(s[j-1]=='1')d=c%5-1;
					else if(s[j-1]=='6'||s[j-1]=='8')d=c%4-1;
					else d=c%3-1;
					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 ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

const string code[9] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  ll n;
  cin >> n;
  rep(i,n){
    cin >> s;
    ll cnt = 0,num = 0;
    bool f = false;
    string ans = "";
    rep(j,s.size()){
      if(!f && s[j] != '0'){
        num = s[j] - '0' - 1;
        cnt = 0;
        f = true;
      }
      else{
        if(s[j] == '0'){
          if(f)
            ans += code[num][cnt];
          f = false;
        }
        else{
          ++cnt;
          cnt %= code[num].size();
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<stdlib.h>
#include<vector>

using namespace std;

int main(){
  int n,cnt=0;
  string s,before="",tmp,key;
  vector<string> keys{".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    if (s.length()==1) {
      cout << endl;
      continue;
    }
    for(int i=0;i<s.length();i++){
      tmp = s[i];
      if (tmp!="0" && tmp==before) cnt++;
      else if (tmp==before) continue;
      else if (tmp=="0"){
        key = keys[atoi(before.c_str())-1][(cnt-1)%(keys[atoi(before.c_str())-1].length())];
        cout << key;
        cnt=0;
        before="0";
      } else {
        before =tmp;
        cnt++;
      } 
    }
    cout << endl;
    
  }
  return 0;
    
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
	int n, i, j, k, c, d, x, a;
	char s[1025], r[76], t[10][6] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> s;
		for (j = x = a = 0, d = 0; j < strlen(s); j++, d = c)
		{
			c = s[j] - '0';
			if (c == 0 && d != 0)
				r[a] = t[d-1][x%strlen(t[d-1])], a++;
			else if (d == c)
				x++;
			else
				x = 0;
		}
		r[a] = '\0';
		cout << r << endl;
	}
}