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 <bits/stdc++.h>

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

using namespace std;

vector<vector<char>> v(10);

string solve() {
	string s; cin >> s;
	string res;
	char c = 0;
	int p = 0;
	rep(i, s.size()) {
		if (s[i] == '0') {
			if (c) res += c;
			p = c = 0;
		} else {
			c = v[s[i]-'0'][p];
			p = (p + 1) % v[s[i]-'0'].size();
		}
	}
	return res;
}

signed main() {
	int n; cin >> n;
	v[1] = vector<char>{'.', ',', '!', '?', ' '};
	v[2] = vector<char>{'a', 'b', 'c'};
	v[3] = vector<char>{'d', 'e', 'f'};
	v[4] = vector<char>{'g', 'h', 'i'};
	v[5] = vector<char>{'j', 'k', 'l'};
	v[6] = vector<char>{'m', 'n', 'o'};
	v[7] = vector<char>{'p', 'q', 'r', 's'};
	v[8] = vector<char>{'t', 'u', 'v'};
	v[9] = vector<char>{'w', 'x', 'y', 'z'};
	while (n--) cout << solve() << endl;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  string ch[10];
  ch[1] = ".,!? ";
  ch[2] = "abc";
  ch[3] = "def";
  ch[4] = "ghi";
  ch[5] = "jkl";
  ch[6] = "mno";
  ch[7] = "pqrs";
  ch[8] = "tuv";
  ch[9] = "wxyz";
  int n;
  cin>>n;
  string inp;
  while(n--){
    cin>>inp;
    REP(i,inp.size()){
      if(inp[i]=='0') continue;
      int count = inp.find("0",i) - i-1;
      int num = inp[i] - '0';
      putchar( ch[num][count%ch[num].size()] );
      i += count + 1;
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;

char num1[5]={'.', ',', '!', '?', ' '};
char num2[]="abc", num3[]="def", num4[]="ghi", num5[]="jkl", num6[]="mno", num7[]="pqrs", num8[]="tuv", num9[]="wxyz";

char func(int x, int y);

int main()
{
	int n, ch;
	cin >> n;
	ch = getchar();
	for(int i = 0; i < n; i++){
		int c1, c2=-1, c3=0;
		char c;
		while(1){
			c1 = getchar();
			if(c1 == '\n'){
				cout << endl;
				c3 = 0;
				break;
			} else if(c1 == '0'){
				if(c2 != -1){
					c = func(c2, c3);
					cout << c;
					c3 = 0;
				}
			} else {
				if(c1 == c2) c3++;
				else {
					c1 = c1 - '0';
					c2 = c1;
					c3++;
				}
			}
		}
	}
	return 0;
}

char func(int x, int y)
{
	int z;
	if(x == 1) return num1[(y-1)%5];
	else if(x == 2) return num2[(y-1)%3];
	else if(x == 3) return num3[(y-1)%3];
	else if(x == 4) return num4[(y-1)%3];
	else if(x == 5) return num5[(y-1)%3];
	else if(x == 6) return num6[(y-1)%3];
	else if(x == 7) return num7[(y-1)%4];
	else if(x == 8) return num8[(y-1)%3];
	else return num9[(y-1)%4];
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>


int main()
{
	int i,j,k;
	int n,m;
	int a[10]={0}; //押された回数
	int b[10]={0,5,3,3,3,3,3,4,3,4}; //割り算	 
	int c; //押されたボタン
	char d[5][10]={
	{'0',' ','c','f','i','l','o','s','v','z'},
	{'0','.','a','d','g','j','m','p','t','w'},
	{'0',',','b','e','h','k','n','q','u','x'},
	{'0','!','0','0','0','0','0','r','0','y'},
	{'0','?','0','0','0','0','0','0','0','0'}};
	char e[1025];
	
	scanf("%d",&n);

	for(i=0;i<n;i++)
	{
		scanf("%s",e);
		for(j=0;j<strlen(e);j++)
		{
			if(e[j]=='0'){
				printf("%c",d[a[c]%b[c]][c]);
				a[c]=0;
			}else
			{
				if(e[j]=='1')c=1;
				else if(e[j]=='2')c=2;
				else if(e[j]=='3')c=3;
				else if(e[j]=='4')c=4;
				else if(e[j]=='5')c=5;
				else if(e[j]=='6')c=6;
				else if(e[j]=='7')c=7;
				else if(e[j]=='8')c=8;
				else if(e[j]=='9')c=9;
				a[c]++;
			}
		}
		printf("\n");
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  string keys[] = {
    "",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz",
  };
  int n;
  string s;
  int kind;
  int cur;

  cin >> n;
  for( int lp=0;lp<n;lp++ ){
    cin >> s;

    //    cout << "s=" << s << endl;
    cur=-1;
    for( unsigned int i=0;i<s.length();i++ ){
      //      cout<<"s[i]="<<s[i]<<" cur="<<cur<<" kind="<<kind<<endl;

      if( s[i]=='0' ){
	if( cur>=0 ){
	  cout << keys[ kind][cur%keys[kind].length() ] ;
	  cur=-1;
	}
      }else{
	if( cur<0 ){
	  kind = s[i] - '0';
	  cur=0;
	}else
	  cur++;
      }
    }
    cout << endl;

    //    break;
  }

  return 0;
}