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(){
	int n;
	string in, out;
	vector<string> trans(10);
	trans[0] = "";
	trans[1] = ".,!? ";		trans[2] = "abc";	trans[3] = "def";
	trans[4] = "ghi";		trans[5] = "jkl";	trans[6] = "mno";
	trans[7] = "pqrs";		trans[8] = "tuv";	trans[9] = "wxyz";
	cin >> n;
	for( int k=0; k<n; k++ ){
		cin >> in;
		out = "";
		int cnt=0;
		for( int i=0; i<in.length(); i++ ){
			if( in[i] == '0' ){
				if( cnt > 0 ){
//					cout << "out:trans[" << in[i-1] << "][" << cnt << "%trans[" << in[i-1] << "].length]" << endl;
					out += trans[in[i-1]-'0'][(cnt-1)%trans[in[i-1]-'0'].length()];
					cnt = 0;
				}
			}else	cnt++;
		}
		cout << out << endl;
	}
	return 0;
}

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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main() {
    int T;
    cin >> T;

    vector<string> vcs = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

    for(int t=0; t<T; t++) {
        string s;
        cin >> s;

        int idx = -1;
        int num = 0;
        bool flag = false;
        for(int i=0; i<s.length(); i++){
            //cout << i <<" "<< s[i] <<" "<< idx << endl;
            if (s[i] == '0') {
                //cout << i <<" num:"<< num <<" idx:"<< idx <<" flag:"<< flag << endl;
                if (!flag) cout << "";
                else cout << vcs[num-1][idx];
                //cout << endl;
                idx = -1;
                flag = false;
            } else {
                flag = true;
                num = s[i] - '0';
                idx = (idx+1)%vcs[num-1].length();
                //cout << vcs[num-1][idx] << endl;
            }
            //cout << s[i] << endl;
        }
        cout << endl;
    }
}

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

string a[10] = {"", ".,!?", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
string s;

string solve(){
  string t = "";

  int key=0, cnt=0;
  for(int i=0; i<(int)s.size(); i++){
    int S = s[i] - '0';
    if(S==0){
      if(key!=0){
        cnt--;
        int len=a[key].size();
        t.push_back(a[key][cnt%len]);
      }
      cnt=key=0;
    } else if(key==S){
      cnt++;
    } else {
      key=S;
      cnt=1;
    }
  }
  return t;
}

int main(){
  int n;
  cin >> n;
  while(n--){
    cin >> s;
    cout << solve() << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)

void b(int a,int count){
  if(a == 1){
    if(count%5==1) cout <<".";
    else if(count%5==2) cout <<",";
    else if(count%5==3) cout <<"!";
    else if(count%5==0) cout <<" ";

  }
  else if(a == 2){
    if(count%3==1) cout <<"a";
    else if(count%3==2) cout <<"b";
    else if(count%3==0) cout <<"c";
  }
  else if(a == 3){
    if(count%3==1) cout <<"d";
    else if(count%3==2) cout <<"e";
    else if(count%3==0) cout <<"f";
  }
  else if(a == 4){
    if(count%3==1) cout <<"g";
    else if(count%3==2) cout <<"h";
    else if(count%3==0) cout <<"i";
  }
  else if(a == 5){
    if(count%3==1) cout <<"j";
    else if(count%3==2) cout <<"k";
    else if(count%3==0) cout <<"l";
  }
  else if(a == 6){
    if(count%3==1) cout <<"m";
    else if(count%3==2) cout <<"n";
    else if(count%3==0) cout <<"o";
  }
  else if(a == 7){
    if(count%4==1) cout <<"p";
    else if(count%4==2) cout <<"q";
    else if(count%4==3) cout <<"r";
    else if(count%4==0) cout <<"s";
  }
  else if(a == 8){
    if(count%3==1) cout <<"t";
    else if(count%3==2) cout <<"u";
    else if(count%3==0) cout <<"v";
  }
  else if(a == 9){
    if(count%4==1) cout <<"w";
    else if(count%4==2) cout <<"x";
    else if(count%4==3) cout <<"y";
    else if(count%4==0) cout <<"z";
  }
  return;
}


int main(){

  int n;
  cin >> n;

  rep(i,0,n){
    string s;
    cin >> s;


    char pre[] = "0\0";
    pre[0]=s[0];
    int count = 0;
    rep(i,0,s.size()){
      if(pre[0] == s[i]){
	count++;
      }
      else{
	int bo = atoi(pre);
	b( bo,count);
	count=1;
	pre[0]=s[i];
      }
    }
    cout << endl;
  }
  return 0;
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

string moji[10];

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