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>

using namespace std;

int main()
{
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string msg;
        string output = "";
        int count = 0;
        char buf;

        cin >> msg;

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

            if (c == '0' && j != 0) {
                if (buf == '1') {
                    if (count % 5 == 1)
                        output += ".";
                    else if (count % 5 == 2)
                        output += ",";
                    else if (count % 5 == 3)
                        output += "!";
                    else if (count % 5 == 4)
                        output += "?";
                    else if (count % 5 == 0)
                        output += " ";
                } else if (buf == '2') {
                    if (count % 3 == 1)
                        output += "a";
                    else if (count % 3 == 2)
                        output += "b";
                    else if (count % 3 == 0)
                        output += "c";
                } else if (buf == '3') {
                    if (count % 3 == 1)
                        output += 'd';
                    else if (count % 3 == 2)
                        output += 'e';
                    else if (count % 3 == 0)
                        output += 'f';
                } else if (buf == '4') {
                    if (count % 3 == 1)
                        output += 'g';
                    else if (count % 3 == 2)
                        output += 'h';
                    else if (count % 3 == 0)
                        output += 'i';
                } else if (buf == '5') {
                    if (count % 3 == 1)
                        output += 'j';
                    else if (count % 3 == 2)
                        output += 'k';
                    else if (count % 3 == 0)
                        output += 'l';
                } else if (buf == '6') {
                    if (count % 3 == 1)
                        output += 'm';
                    else if (count % 3 == 2)
                        output += 'n';
                    else if (count % 3 == 0)
                        output += 'o';
                } else if (buf == '7') {
                    if (count % 4 == 1)
                        output += 'p';
                    else if (count % 4 == 2)
                        output += 'q';
                    else if (count % 4 == 3)
                        output += 'r';
                    else if (count % 4 == 0)
                        output += 's';
                } else if (buf == '8') {
                    if (count % 3 == 1)
                        output += 't';
                    else if (count % 3 == 2)
                        output += 'u';
                    else if (count % 3 == 0)
                        output += 'v';
                } else if (buf == '9') {
                    if (count % 4 == 1)
                        output += 'w';
                    else if (count % 4 == 2)
                        output += 'x';
                    else if (count % 4 == 3)
                        output += 'y';
                    else if (count % 4 == 0)
                        output += 'z';
                }
                count = 0;
                buf = '\0';
            } else {
                count++;
                buf = msg[j];
            }
        }
        cout << output << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i < t ; i++)
#define SZ(a) (int)a.size()

char img[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 in1[9] = { 5,3,3,3,3,3,4,3,4 };

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int Case;
	cin >> Case;
	FOR(kim, 0, Case) {
		string s;
		cin >> s;
		int i = 0;
		while (i != SZ(s)) {
			int co = 0;
			while (s[i] != '0') {
				co++;
				i++;
			}
			if (co) {
				int target = s[i - 1] - '0' - 1;
				int pos = (co - 1) % (in1[target]);
				cout << img[target][pos];
			}
			i++;
		}
		cout << endl;
	}
}

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

int main(){
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
  string s;
  cin>>s;
  char u=' ', b=0;
  char p[]={' ','.', 'a','d','g','j','m','p','t','w'};
  string t="";
  for(int i=0; i<s.size();i++) {
    int x=s[i]-'0';
    if (x==0) {
      if (b>0) {
      if (u=='.') {
        char f[]={'.',',','!','?'};
        t+=string(1, f[b-1]);
      } else {
        t+=string(1, (char)(u+b-1));
      }
      b = 0;
      }
    } else {
      u=p[x];
      b++;
      if ((x==7||x==9)&&b==5) b=1;
      if (b==4) b=1;
    }
  }
  cout<<t<<endl;
}
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	
	vector<string> v(10);
	v[1] = ".,!? ";
	v[2] = "abc";
	v[3] = "def";
	v[4] = "ghi";
	v[5] = "jkl";
	v[6] = "mno";
	v[7] = "pqrs";
	v[8] = "tuv";
	v[9] = "wxyz";
	
	int n;
	cin >> n;
	rep(i, n){
		string s, ans;
		cin >> s;
		rep(j, s.size()){
			int cnt = 0;
			if(s[j] == '0') continue;
			while(s[j] == s[j+1]){
				j++;
				cnt++;
			}
			int num = (int)(s[j] - '0');
			ans += v[num][cnt % v[num].size()]; 
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


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

int mod[10] = { 1,5,3,3,3,3,3,4,3,4 };

int main()
{
	cin >> n;
	REP(i, n)
	{
		cin >> s;

		cnt = 0;
		string ans;

		REP(i, s.size())
		{
			if (s[i] != '0') {
				cnt++;
			} else {
				if (cnt != 0) {
					ans += table[s[i - 1] - '0'][(cnt - 1) % mod[s[i - 1] - '0']];
					cnt = 0;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}