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<stdio.h>
int main()
{
  char c;
  int n;
  int out;
  int end;
  int i;
  scanf("%d",&n);
  for(i=0;i<n+1;i++)
    {
      end=0;
      while(1)
	{
	  out=0;
	  while(1)
	    {
	      scanf("%c",&c);
	      if(out==0)
		{
		  switch(c)
		    {
		    case '1':
		      out=1;
		      break;
		    case '2':
		      out=6;
		      break;
		    case '3':
		      out=9;
		      break;
		    case '4':
		      out=12;
		      break;
		    case '5':
		      out=15;
		      break;
		    case '6':
		      out=18;
		      break;
		    case '7':
		      out=21;
		      break;
		    case '8':
		      out=25;
		      break;
		    case '9':
		      out=28;
		      break;
		    }
		}
	      else
		{
		  switch(c)
		    {
		    case '1':
		      if(out==5) out=1;
		      else out++;
		      break;
		    case '2':
		      if(out==8) out=6;
		      else out++;
		      break;
		    case '3':
		      if(out==11) out=9;
		      else out++;
		      break;
		    case '4':
		      if(out==14) out=12;
		      else out++;
		      break;
		    case '5':
		      if(out==17) out=15;
		      else out++;
		      break;
		    case '6':
		      if(out==20) out=18;
		      else out++;
		      break;
		    case '7':
		      if(out==24) out=21;
		      else out++;
		      break;
		    case '8':
		      if(out==27) out=25;
		      else out++;
		      break;
		    case '9':
		      if(out==31) out=28;
		      else out++;
		      break;
		    }
		}
	      if(c=='\n')
		{
		  end=1;
		  break;
		}
	      if(c=='0') break;
	    }
	  switch(out)
	    {
	    case 1:
	      printf(".");
	      break;
	    case 2:
	      printf(",");
	      break;
	    case 3:
	      printf("!");
	      break;
	    case 4:
	      printf("?");
	      break;
	    case 5:
	      printf(" ");
	      break;
	    case 6:
	      printf("a");
	      break;
	    case 7:
	      printf("b");
	      break;
	    case 8:
	      printf("c");
	      break;
	    case 9:
	      printf("d");
	      break;
	    case 10:
	      printf("e");
	      break;
	    case 11:
	      printf("f");
	      break;
	    case 12:
	      printf("g");
	      break;
	    case 13:
	      printf("h");
	      break;
	    case 14:
	      printf("i");
	      break;
	    case 15:
	      printf("j");
	      break;
	    case 16:
	      printf("k");
	      break;
	    case 17:
	      printf("l");
	      break;
	    case 18:
	      printf("m");
	      break;
	    case 19:
	      printf("n");
	      break;
	    case 20:
	      printf("o");
	      break;
	    case 21:
	      printf("p");
	      break;
	    case 22:
	      printf("q");
	      break;
	    case 23:
	      printf("r");
	      break;
	    case 24:
	      printf("s");
	      break;
	    case 25:
	      printf("t");
	      break;
	    case 26:
	      printf("u");
	      break;
	    case 27:
	      printf("v");
	      break;
	    case 28:
	      printf("w");
	      break;
	    case 29:
	      printf("x");
	      break;
	    case 30:
	      printf("y");
	      break;
	    case 31:
	      printf("z");
	      break;
	    }
	  if(end) break;
	}
      if(i!=0) printf("\n");	 
    }
  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int n;
string s;

string bt[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
int ln[] = {5, 3, 3, 3, 3, 3, 4, 3, 4};

int main()
{
  cin >> n;

  while(n--){
    cin >> s;
    int ptr = 0;
    while(ptr < s.size()){
      int cnt = 0;
      while(ptr < s.size() && s[ptr] == '0') ptr += 1;
      if(ptr >= s.size()) break;
      while(ptr < s.size() - 1 && s[ptr] == s[ptr + 1]){
        cnt += 1;
        ptr += 1;
      }
      if(ptr >= s.size()) break;
      cout << bt[s[ptr]-'0'-1][cnt % (ln[s[ptr]-'0'-1])];
      if(ptr >= s.size()) break;
      ptr += 1;
    }
    cout << endl;
  }

  return 0;
}

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

using namespace std;

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

    cin >> n;

    while (n--) {
        string msg, ans, t;

        cin >> msg;

        ans = ""; j = 0; t = "";

        for (int i = 0; i < msg.size(); i++) {
            if (msg[i] == '0') {
                ans += t;
                j = 0; t = "";
            }
            else {
                t = table[msg[i]-'0'-1][j];
                j++;
                j %= table[msg[i]-'0'-1].size();
            }
        }
        cout << ans << endl;
    }
    return 0;
}