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>
#include <cstdlib>
using namespace std;

#define MAXLEN 1024
#define MAXCHAR 76

char judge(char c, int x){
  int i;

  if(c == '1'){
    i = x % 5;

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

}

void ret_char(char *s, int sp, char *r){
  if(*s != '\0'){
    if(*s == '0'){
      if(sp != 0){
	*r = judge(*(s - 1), sp);
	sp = 0;
	s++;
	r++;
	ret_char(s, sp, r); // 再帰
      } else {
	s++;
	ret_char(s, sp, r); // 再帰
      }
    } else {
      s++;
      sp++;
      ret_char(s, sp, r); // 再帰
    }
  }

}

main(){
  int testcase, i, j, count = 0;
  char message[MAXLEN + 1], *rechar = (char *)malloc(sizeof(char) * MAXCHAR);

  cin >> testcase;

  for (i = 0; i < testcase; i++){
    scanf("%s", message);
    message[strlen(message)] = '\0';
    ret_char(message, 0, rechar);
    strcpy(message, "");
    strcpy(rechar, "");
  }

  return 0;
}

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

int main(){
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
  string s;
  cin>>s;
  char u=' ', b=0;
  char p[]={' ','.', 'a','d','g','j','m','p','t','w'};
  string t="";
  for(int i=0; i<s.size();i++) {
    int x=s[i]-'0';
    if (x==0) {
      if (b>0) {
      if (u=='.') {
        char f[]={'.',',','!','?'};
        t+=string(1, f[b-1]);
      } else {
        t+=string(1, (char)(u+b-1));
      }
      b = 0;
      }
    } else {
      u=p[x];
      b++;
      if ((x==7||x==9)&&b==5) b=1;
      if (b==4) b=1;
    }
  }
  cout<<t<<endl;
}
  return 0;
}

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

vs a(9);

int main(){
	a[0]=".,!? ";
	a[1]="abc";
	a[2]="def";
	a[3]="ghi";
	a[4]="jkl";
	a[5]="mno";
	a[6]="pqrs";
	a[7]="tuv";
	a[8]="wxyz";
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			int id=-1,cnt=0;
			for(auto c:s){
				if(c=='0'){
					if(id>=0){
						cout<<a[id][(cnt-1)%a[id].size()];
						id=-1;
						cnt=0;
					}
				}
				else{
					id=c-'1';
					cnt++;
				}
			}
			cout<<endl;
		}
		break;
	}
}

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

#define rep(i,n) for(int i=0; i<n; i++)

int size[9]={5, 3, 3, 3, 3, 3, 4, 3, 4};
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 main(){
  int n;
  cin>>n;
  rep(i,n){
    string s;
    cin>>s;
    int c=0, cnt=0;
    rep(j,s.length()){
      if(s[j]=='0'){
        if(c==0)continue;
        cout<<a[c-1][(cnt-1)%size[c-1]];
        c=0; cnt=0;
      }
      else{
        c=(s[j]-'0');
        cnt++;
      }
    }
    cout<<endl;
  }
  return 0;
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;


int main() {
	ios::sync_with_stdio(false);
	string s[10] = { "",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" };
	cin >> N;
	for (int i = 0; i < N; i++) {
		string t;
		string ret;
		cin >> t;
		int box = 0;
		int bag = 0;
		for (auto j : t) {
			if (j == '0') {
				if (box) {
					ret += s[bag][(box - 1) % s[bag].size()];
				}
				box = 0;
			}
			else {
				if (bag == (int)(j - '0'))box++;
				else {
					bag = j - '0';
					box = 1;
				}
			}
		}
		cout << ret << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
  string code[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  int len[] = {5, 3, 3, 3, 3, 3, 4, 3, 4};
  
  int N;
  cin >> N;
  while(N--){
    string s;
    cin >> s;
    char c = '\0';
    int idx = 0;
    for(int i = 0; i < s.size(); i++){
      if(s[i] == '0'){
	cout << c;
	c = '\0';
	idx = 0;
      } else {
	c = code[s[i]-'0'-1][idx];
	idx = (idx + 1) % len[s[i]-'0'-1];
      }
    }
    cout << endl;
  }

  return 0;
}