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 <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
#define MAXNUM 1024
using namespace std;
typedef long long ll;

int main(){
  int n; cin >> n;
  string dict[10] = {
    {""},
    {".,!?"},
    {"abc"},
    {"def"},
    {"ghi"},
    {"jkl"},
    {"mno"},
    {"pqrs"},
    {"tuv"},
    {"wxyz"},
  };

  REP(i, n){
    string input;  cin >> input;
    int num = 0, cnt=-1;
    REP(j, input.length()){
      if(input[j] != '0'){
        if(num==0)  num = input[j] - '0';
        cnt++;
        continue;
      }else{
        if(num!=0){
          cnt %= dict[num].length();
          cout << dict[num][cnt];
          cnt = -1;
          num = 0;
        }
      }
    }
    cout << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, 0, 1, -1 , 1,  1, -1, -1 };

int n;
string str;
VS input(9);

string now;
PII many_push;

int gcd( int m, int n ) {
	if ( n == 0 ) return m;
	return gcd( n, m % n );
}

int main() {
	input[ 0 ] = ".,!? ";
	input[ 1 ] = "abc";
	input[ 2 ] = "def";
	input[ 3 ] = "ghi";
	input[ 4 ] = "jkl";
	input[ 5 ] = "mno";
	input[ 6 ] = "pqrs";
	input[ 7 ] = "tuv";
	input[ 8 ] = "wxyz";
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		cin >> str;
		many_push = PII( 10, 10 );
		now = "(";
		for ( int j = 0; j < str.size(); j++ ) {	
			if ( str[ j ] == '0' ) {
				if ( now[ 0 ] != '(' ) {
					cout << now;
					now[ 0 ] = '(';
				}
				continue;
			}
			if ( many_push.first != str[ j ] - '1' ) {
				many_push = PII( str[ j ] - '1', 0 );
				now[ 0 ] = input[ many_push.first ][ many_push.second ];
				continue;
			}
			many_push.second++;
			many_push.second %= input[ many_push.first ].size();
			now[ 0 ] = input[ many_push.first ][ many_push.second ];
		}
		printf( "\n" );
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;

int main(){
  char ch[10][6] = { {""},
		     {".,!? "},
		     {"abc"},
		     {"def"},
		     {"ghi"},
		     {"jkl"},
		     {"mno"},
		     {"pqrs"},
		     {"tuv"},
		     {"wxyz"}};

  int n;
  scanf("%d", &n);
  while(n--){
    string s;
    cin >> s;
    int f = 0, c = 0, k = 0;
    rep(i, s.size()){
      if(s[i] == '0'){
	//	printf("%d %d\n", k, c-1);
	if(f) printf("%c", ch[k][(c-1)%strlen(ch[k])]);
	f = 0;
	c = 0;
	k = 0;
      }else{
	f = 1;
	c++;
	k = s[i]-'0';
	//	printf("%d %d %d\n", f, c, k);
      }
    }
    puts("");
  }
  return 0;
}