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++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int INF=1000000;
char fi[101][101];
int d[21][21];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;

int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003

int dp[353][353]={0};
int bow[353][353]={0};


int main(){
	
	string s;
	
	while(cin>>s){
		vector<string> p(10);
		p[1]=".,!? ";
		p[2]="abc";
		p[3]="def";
		p[4]="ghi";
		p[5]="jkl";
		p[6]="mno";
		p[7]="pqrs";
		p[8]="tuv";
		p[9]="wxyz";
		bool f=false;
		char c='0';
		int count=0;
		string a="";
		rep(i,s.size()){
			if(s[i]=='0'){
				if(f){
				if(c=='1'){
					count=(count-1)%5;
				}
				else if(c=='7'&&c=='9'){
					count=(count-1)%4;
				}
				else{
					count=(count-1)%3;
				}
				a+=p[c-'0'][count];
				f=false;
				count=0;
				}
			}
			else{
				f=true;
				if(c!=s[i]){
					c=s[i];
					count=1;
				}
				else
					count++;
				
			}
			
		}
		cout<<a<<endl;
	}
	
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>

int main(void)
{
  int n;
  char buf[1025];
  int count=0;
  int tmp;

  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s",buf);
    for(int j=0;buf[j]!='\0';j++){
      if(buf[j]=='\n')continue;
      
      if(buf[j]!='0'){
	tmp = buf[j]-'0';
	count++;
      }
      else{
	if(count==0){continue;}
	switch(tmp){
	case 1:
	  if(count%4==1)printf(".");
	  if(count%4==2)printf(",");
	  if(count%4==3)printf("!");
	  if(count%4==0)printf("?");
	  break;
	case 2:
	  if(count%3==1)printf("a");
	  if(count%3==2)printf("b");
	  if(count%3==0)printf("c");
	  break;
	case 3:
	  if(count%3==1)printf("d");
	  if(count%3==2)printf("e");
	  if(count%3==0)printf("f");
	  break;
	case 4:
	  if(count%3==1)printf("g");
	  if(count%3==2)printf("h");
	  if(count%3==0)printf("i");
	  break;
	case 5:
	  if(count%3==1)printf("j");
	  if(count%3==2)printf("k");
	  if(count%3==0)printf("l");
	  break;
	case 6:
	  if(count%3==1)printf("m");
	  if(count%3==2)printf("n");
	  if(count%3==0)printf("o");
	  break;
	case 7:
	  if(count%4==1)printf("p");
	  if(count%4==2)printf("q");
	  if(count%4==3)printf("r");
	  if(count%4==0)printf("s");
	  break;
	case 8:
	  if(count%3==1)printf("t");
	  if(count%3==2)printf("u");
	  if(count%3==0)printf("v");
	  break;
	case 9:
	  if(count%4==1)printf("w");
	  if(count%4==2)printf("x");
	  if(count%4==3)printf("y");
	  if(count%4==0)printf("z");
	  break;
	}
	count=0;
      }
    }
    printf("\n");
  }
      
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int n; cin >> n;
	string s[10];
	s[0] = '0';
	s[1] = ".,!? ";
	s[2] = "abc";
	s[3] = "def";
	s[4] = "ghi";
	s[5] = "jkl";
	s[6] = "mno";
	s[7] = "pqrs";
	s[8] = "tuv";
	s[9] = "wxyz";
	for (int i = 0; i < n; i++) {


		string num;
		cin >> num;
		for (int j = 0; j < num.size(); j++) {
			if (j == 0) {
				if (num[j] == '0') {
					continue;
				}
			}

			else if (num[j - 1] == '0'&&num[j] == '0') {
				continue;
			}
			int t = 0;
			while (num[j + t] != '0')t++;
			switch (num[j]) {
			case '1':cout << s[1][(t - 1) % 5]; break;
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':cout << s[num[j]-'0'][(t-1) % 3]; break;
			case '9':cout << s[9][(t-1) % 4]; break;
			default:break;
			}
			j += t;
		}
		cout << endl;






	}
	return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

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


int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    int cnt = 0;
    for(int j = 0; j < s.size(); j++){
      if(s[j] == '0'){
        if(cnt != 0){
          char c;
          int num = s[j-1] - '0';
          // cout << "num: " << num - 1 << " " << (cnt-1)%button[num-1].size() << endl;
          if(num - 1 == 0 && (cnt-1)%button[num-1].size() == 4)c = ' ';
          else c = button[num - 1][(cnt-1)%button[num-1].size()];
          cout << c;
          cnt = 0;
        }
      }else{
        cnt++;
      }
    }
    cout << endl;
  }
}