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 <string>
#include <vector>

using namespace std;

string button[9] = {".,!?", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

int main(void){
  int n;
  string s;

  cin >> n;
  for(int i=0; i<n; i++){
    vector<char> v;
    cin >> s;

    int count = 0;
    for(int j=0; j<s.size(); j++){
      if(s[j] == '0'){
        if(j == 0 || s[j-1] == '0')
          continue;

        v.push_back(button[(s[j-1]-'0')-1][(count-1)%button[(s[j-1]-'0')-1].size()]);
        count = 0;
      } else {
        count++;
      }
    }

    for(int j=0; j<v.size(); j++){
      cout << v[j];
    }
    cout << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;

char outc(int button, int cnt) {
  static char s[10] = {' ',' ','a','d','g','j','m','p','t','w'};
  static int a[10] = {0,0,3,3,3,3,3,4,3,4};
  if(button == 1) {
    switch(cnt%5) {
    case 1:return '.';
    case 2:return ',';
    case 3:return '!';
    case 4:return '?';
    case 0:return ' ';
    }
  } else {
    return s[button] +  (cnt-1)%a[button];
  }
}

main() {
  int N;
  int button;
  int cnt;
  cin >> N;
  getchar();
  for(int t = 0; t < N; t++) {
    button = 0;
    while(1) {
      char c = getchar();
      if(button == 0 && c != '0') {
	button = int(c-'0');
	cnt = 1;
      } else if(button != 0 && c == '0') {
	cout << outc(button, cnt);
	button = 0;
      } else {
	cnt++;
      }
      if(c == '\n') break;
    }
    cout << endl;
  }
}

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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  string but[10] = {
	"",
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz",
  };
  REP(t,N){
	string str; cin >> str;
	int cur = -1, p = -1;
	REP(i,SZ(str)){
	  if(str[i] == '0' && p > 0){
		cout << but[p][cur%SZ(but[p])];
		cur = p = -1;
	  }
	  else{
		p = str[i] - '0';
		++cur;
	  }
	}
	cout << endl;
  }
  return 0;
}

C++: 

#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-9;

typedef pair<xy_t, bool> dat;

namespace std{
	bool operator < (const xy_t &a, const xy_t &b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

string chs[] = {
	".,!? ", 
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz"
};

int main(){
	int n;
	string s;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s;
		int pos = 0;
		int sz = s.size();
		while(pos < sz){
			while(pos < sz && s[pos] == '0') pos++;
			if(pos == sz) break;
			char ch = s[pos];
			int cnt = 0;
			while(pos < sz && s[pos] == ch) cnt++, pos++;
			cout << chs[ch-'1'][(cnt-1)%chs[ch-'1'].size()];
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

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

    for (int i = 0; i < n; i++) {
        string msg;
        int count = 0;
        char prev = '0';

        cin >> msg;

        for (int j = 0; j < msg.size(); j++) {
            char c = msg[j];

            if (c == '0') {
                if (prev == '1') {
                    cout << messages[0][(count-1) % 5];
                } else if (prev == '2') {
                    cout << messages[1][(count-1) % 3];
                } else if (prev == '3') {
                    cout << messages[2][(count-1) % 3];
                } else if (prev == '4') {
                    cout << messages[3][(count-1) % 3];
                } else if (prev == '5') {
                    cout << messages[4][(count-1) % 3];
                } else if (prev == '6') {
                    cout << messages[5][(count-1) % 3];
                } else if (prev == '7') {
                    cout << messages[6][(count-1) % 4];
                } else if (prev == '8') {
                    cout << messages[7][(count-1) % 3];
                } else if (prev == '9') {
                    cout << messages[8][(count-1) % 4];
                }
                count = 0;
            } else {
                count++;
            }
            prev = msg[j];
        }
        cout << endl;
    }

    return 0;
}