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 <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";

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

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

			cout << output << endl;
	
		}	
	}
}

C++: #include <bits/stdc++.h>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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

	cin >> n;
	FOR(i, 1, n) {
		cin >> s;
		int count = 0;
		int now = 0;
		FOR(t, 0, s.size() - 1) {
			if (s[t] == '0') {
				if (now == 1) {
					switch (count % 5) {
					case 0:
						cout << " ";
						break;
					case 1:
						cout << ".";
						break;
					case 2:
						cout << ",";
						break;
					case 3:
						cout << "!";
						break;
					case 4:
						cout << "?";
						break;
					}
				}
				else if (now == 7) {
					switch (count % 4) {
					case 0:
						cout << "s";
						break;
					case 1:
						cout << "p";
						break;
					case 2:
						cout << "q";
						break;
					case 3:
						cout << "r";
						break;
					}
				}
				else if (now == 9) {
					switch (count % 4) {
					case 0:
						cout << "z";
						break;
					case 1:
						cout << "w";
						break;
					case 2:
						cout << "x";
						break;
					case 3:
						cout << "y";
						break;
					}
				}
				else if (now == 2) {
					switch (count % 3) {
					case 0:
						cout << "c";
						break;
					case 1:
						cout << "a";
						break;
					case 2:
						cout << "b";
						break;
					}
				}
				else if (now == 3) {
					switch (count % 3) {
					case 0:
						cout << "f";
						break;
					case 1:
						cout << "d";
						break;
					case 2:
						cout << "e";
						break;
					}
				}
				else if (now == 4) {
					switch (count % 3) {
					case 0:
						cout << "i";
						break;
					case 1:
						cout << "g";
						break;
					case 2:
						cout << "h";
						break;
					}
				}
				else if (now == 5) {
					switch (count % 3) {
					case 0:
						cout << "l";
						break;
					case 1:
						cout << "j";
						break;
					case 2:
						cout << "k";
						break;
					}
				}
				else if (now == 6) {
					switch (count % 3) {
					case 0:
						cout << "o";
						break;
					case 1:
						cout << "m";
						break;
					case 2:
						cout << "n";
						break;
					}
				}
				else if (now == 8) {
					switch (count % 3) {
					case 0:
						cout << "v";
						break;
					case 1:
						cout << "t";
						break;
					case 2:
						cout << "u";
						break;
					}
				}

				now = 0;
				count = 0;
			}
			else {
				now = s[t] - '0';
				count++;
			}
		}
		cout << endl;
	}
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
vector<vector<char> > c(10, vector<char>(5));
int main()
{
  c[1][0] = '.';c[1][1] = ',';c[1][2] = '!';c[1][3] = '?';c[1][4] = ' ';
  FOR(i,0,3) c[2][i] = 'a' + i;
  FOR(i,0,3) c[3][i] = 'd' + i;
  FOR(i,0,3) c[4][i] = 'g' + i;
  FOR(i,0,3) c[5][i] = 'j' + i;
  FOR(i,0,3) c[6][i] = 'm' + i;
  FOR(i,0,4) c[7][i] = 'p' + i;
  FOR(i,0,3) c[8][i] = 't' + i;
  FOR(i,0,4) c[9][i] = 'w' + i;
  int n;
  cin >> n;
  while(n--) {
    string s;
    cin >> s;
    int cnt = 0;
    char now;
    string ans = "";
    FOR(i,0,s.length()) {
      if(s[i] == '0' && now != '0') {
        cnt--;
        if(now == '1') cnt %= 5;
        else if(now == '7' || now == '9') cnt %= 4;
        else cnt %= 3;
        ans += c[now-'0'][cnt];
        now = '0';
        cnt = 0;
      } else if(s[i] != '0'){
        now = s[i];
        cnt++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

char p(int n, int times) {
    return s[n][(times - 1) % (int)s[n].size()];
}

int main() {
    int N;
    cin >> N;
    string msg;
    while (N --) {
        cin >> msg;
        string t = "";
        for (int i=0; i<(int)msg.size(); ++i) {
            if (msg[i] == '0') {
                if (t != "") {
                    cout << p(t[0] - '0', t.size());
                    t = "";
                }
            } else {
                t += msg[i];
            }
        }
        cout << endl;
    }
    return 0;
}