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++: #if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

char w[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 n;
char c[1030];
int t;
P s[80];
char o[80];
int l;

void input(){
  cin>>c;
  l = strlen(c);
  REP(i, 80)s[i] = mp(0, 0);
}

void solve(){
  t=0;

  REP(i, l) {
    if(c[i]=='0') {
      if(s[t].ft==0)continue;
      else t++;
    }else {
      if(s[t].ft==0)s[t].ft=c[i]-'0';
      else s[t].sd++;
    }
  }

  REP(i, t) {
    s[i].ft--;
    o[i] = w[s[i].ft][s[i].sd%(s[i].ft==0?5:(s[i].ft==6||s[i].ft==8?4:3))];
  }
  o[t] = '\0';
  cout<<o<<endl;
}

int main(){
  cin.tie(0);
  
  cin>>n;
  REP(i, n) {
    input();
    solve();
  }
  
  return 0;
}

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

int main()
{ 
  int n; cin>>n;
  vector<string> ans;
  while(n--)
  {
    string on=".,!? ";
    string s; cin>>s;
    int cnt=0 ,num=0;
    string tmp;
    for(int i=0; i<s.size(); ++i)
    {
      if(num==s[i]-'0') cnt++;
      else 
      {
        if(num==1) tmp+=on[cnt%5];
        else if(num==7) tmp+=cnt%4+'p';
        else if(num==8) tmp+=cnt%3+'t';
        else if(num==9) tmp+=cnt%4+'w';
        else if(num>1) tmp+=cnt%3+'a'+3*(num-2);
        cnt=0;
        num=s[i]-'0';
      }
    }
    ans.emplace_back(tmp);
  }
  for(auto e:ans) cout<<e<<"\n";

  return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
/*

    1: . , ! ? (スペース)
    2: a b c
    3: d e f
    4: g h i
    5: j k l
    6: m n o
    7: p q r s
    8: t u v
    9: w x y z
    0: 確定ボタン */
char keitai[10][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'},
};
string str;
int main()
{
  int n;
  cin >>n;
  for(int i = 0;i < n;i++){
    int cnt[15] = {0};
    cin >>str;
    for(int i = 0;i < str.length();i++){
      if(i >0&&str[i]=='0'&&str[i-1]!='0'){
	if((str[i-1]=='1')){
	  cout <<keitai[(str[i-1]-'0')-1][(cnt[(str[i-1]-'0')]-1)%5];
	  cnt[str[i-1]-'0'] = 0;
	}
	else if((str[i-1]=='7'||str[i-1]=='9')){
	  cout <<keitai[(str[i-1]-'0')-1][(cnt[str[i-1]-'0']-1)%4];
	  cnt[str[i-1]-'0'] = 0;
	}else{
	  cout <<keitai[(str[i-1]-'0')-1][(cnt[str[i-1]-'0']-1)%3];
	  cnt[str[i-1]-'0'] = 0;	  
	}
      }
      if(str[i] !='0'){
	cnt[str[i]-'0'] +=1;
      }
    }
    cout <<endl;
  }
  return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;


int main() {
	int n;
	vs button(10, "");
	vi buttonnum(10, 0);

	button[0] = "";
	button[1] = ".,!? ";
	button[2] = "abc";
	button[3] = "def";
	button[4] = "ghi";
	button[5] = "jkl";
	button[6] = "mno";
	button[7] = "pqrs";
	button[8] = "tuv";
	button[9] = "wxyz";

	cin >> n;
		REP(k, n) {
			string input;
			cin >> input;
			string output = "";
			int size = input.size();
			int lastnum = 0;

			REP(i, size) {
				switch(input[i]) {
				case '0':
					if(lastnum) {
						output += button[lastnum][(buttonnum[lastnum]-1)%button[lastnum].size()];
						buttonnum[lastnum] = 0;
						lastnum = 0;
						break;
					}
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':			
				case '6':			
				case '7':			
				case '8':			
				case '9':
					++buttonnum[input[i]-'0'];
					lastnum = input[i]-'0';
					break;
				}
			}

			cout << output << endl;
	
		
	}
}