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++: // AOJ 2006
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {
  string input;
  string trm = "cfilov";
  while (cin >> input) {
    char c = '\0';
    for (char btn : input) {
      if (c == '\0') {
        if (btn == '1') {
          c = '.';
        } else if (btn == '2') {
          c = 'a';
        } else if (btn == '3') {
          c = 'd';
        } else if (btn == '4') {
          c = 'g';
        } else if (btn == '5') {
          c = 'j';
        } else if (btn == '6') {
          c = 'm';
        } else if (btn == '7') {
          c = 'p';
        } else if (btn == '8') {
          c = 't';
        } else if (btn == '9') {
          c = 'w';
        }
      } else if (btn == '0') {
        cout << c;
        c = '\0';
      } else {
        if (c == 's' or c == 'z') {
          c -= 3;
        } else if (find(trm.begin(), trm.end(), c) != trm.end()) {
          c -= 2;
        } else if (c == '.') {
          c = ',';
        } else if (c == ',') {
          c = '!';
        } else if (c == '!') {
          c = '?';
        } else if (c == '?') {
          c = ' ';
        } else if (c == ' ') {
          c = '.';
        } else {
          c++;
        }
      }
    }
    cout << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <deque>
#include <stack>
#include <algorithm>
#include <memory.h>

#define rep(idx, max)			for(int idx = 0, idx##Max = (max); idx < idx##Max; idx ++)
#define rrep(idx, min, max)	for(int idx = (min), idx##Max = max; idx < idx##Max; idx ++)
#define erep(idx, min, max)	for(int idx = (min), idx##Max = max; idx <= idx##Max; idx ++)

#define rev(idx, max)			for(int idx = (max) - 1; idx >= 0; idx --)
#define rrev(idx, min, max)	for(int idx = (max) - 1, idx##Min = (min); idx >= idx##Min; idx --)
#define erev(idx, min, max)	for(int idx = (max), idx##Min = (min); idx >= idx##Min; idx --)

#define foreach(it, obj)	for(auto it = obj.begin(), it##End = obj.end(); it >= it##End; it ++)

typedef struct	_DEC
{
	const char *lpszText;
	int length;
} DEC;

void	Decrypt(std::string &dst, std::string &src)
{
	static DEC decTbl[] =
	{
		{"", 0 + 1},	// +1 for prevent 0-DIV
		{".,!? ", 5}, {"abc", 3}, {"def", 3}, {"ghi", 3},
		{"jkl", 3}, {"mno", 3}, {"pqrs", 4}, {"tuv", 3},
		{"wxyz", 4},
	};
	for(int pos = 0, len = src.size(); pos < len; pos ++)
	{
		int ch, sectlen = pos;
		for(ch = src[pos]; src[pos] != '0'; pos ++);
		sectlen = pos - sectlen - 1;
		if(int idx = ch - '0')
		{	dst += decTbl[idx].lpszText[sectlen % decTbl[idx].length];	}
	}
}

int main()
{
	int tc;
	std::cin >> tc;
	while(tc --)
	{
		std::string decText;
		std::string encText;
		std::cin >> encText;
		::Decrypt(decText, encText);
		std::cout << decText << std::endl;
	}
}

C++: #include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main(){
  int n,i,j,k,p;
  string str;
  cin>>n;
  for(j=0;j<n;j++){
    cin >> str;
    p=0;
    char c;
    for(i=0;i<str.size();i++){
      if(str[i]=='0'){
	if(p!=0){
	  if(c=='1'){
	    if(p%5==1) cout << '.';
	    if(p%5==2) cout << ',';
	    if(p%5==3) cout << '!';
	    if(p%5==4) cout << '?';
	    if(p%5==0) cout << " ";
	  }
	  if(c=='2'){
	    printf("%c", ('a'+(p-1)%3));
	  }
	  if(c=='3'){
	    printf("%c", ('d'+(p-1)%3));
	  }
	  if(c=='4'){
	    printf("%c", ('g'+(p-1)%3));
	  }
	  if(c=='5'){
	    printf("%c", ('j'+(p-1)%3));
	  }
	  if(c=='6'){
	   printf("%c", ('m'+(p-1)%3));
	  }
	  if(c=='7'){
	    printf("%c", ('p'+(p-1)%4));
	  }
	  if(c=='8'){
	    printf("%c", ('t'+(p-1)%3));
	  }
	  if(c=='9'){
	    printf("%c", ('w'+(p-1)%4));
	  }
	}
	p=0;
      }else{
	c=str[i];
	p++;
      }
      
    }
    cout << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    char lis[10][10]={
        "",
        ".,!? ",
        "abc",
        "def",
        "ghi",
        "jkl",
        "mno",
        "pqrs",
        "tuv",
        "wxyz",
    };
    int n;
    scanf("%d",&n);
    while(n--){
        char str[2024];
        scanf("%s",str);
        int v,cnt=-1;
        for(int i=0;str[i];i++){
            if(str[i]=='0'){
                if(cnt!=-1){
                    printf("%c",lis[v][cnt]);
                    cnt=-1;
                }
            }
            else{
                v=str[i]-'0';
                cnt++;
                cnt%=strlen(lis[v]);
            }
        }
        puts("");
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<string> G(10);
  G[1] = ".,!? ";
  G[2] = "abc";
  G[3] = "def";
  G[4] = "ghi";
  G[5] = "jkl";
  G[6] = "mno";
  G[7] = "pqrs";
  G[8] = "tuv";
  G[9] = "wxyz";
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    string S;
    cin >> S;
    vector<pair<char,int>> vec;
    vec.emplace_back('0',1);
    for(int j=0; j<S.size(); j++){
      if(S[j] == '0'){
        vec.emplace_back('0',1);
      }else{
        if(vec.back().first == S[j]){
          vec.back().second++;
        }else{
          vec.emplace_back(S[j],1);
        }
      }
    }
    string ans = "";
    string temp = "";
    for(int j=0; j<vec.size(); j++){
      if(vec[j].first == '0'){
        ans += temp;
        temp = "";
      }else{
        temp += G[vec[j].first-'0'][(vec[j].second-1)%G[vec[j].first-'0'].size()];
      }
    }
    cout << ans << endl;
  }
  return 0;
}