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<stdlib.h>
#include<string.h>
using namespace std;
const char button[10][6] = {	{},
								{'.',',','!','?',' '},
								{'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',}};
const int num[10] = {0,5,3,3,3,3,3,4,3,4};
int main()
{
	int n;
	cin >> n;
	char line[1024];
	for (int i = 0; i < n; i++)
	{
		cin >> line;
		int len = strlen(line);
		int j = 0;
		while (j < len)
		{
			int next = j + 1;
			int count = 0;
			while(next < len  && line[next] == line[j])
			{
				next++;
				count++;
			}
			if ((line[j] - '0') != 0)
			{
				int number = line[j] - '0';
				int length = num[number];
				cout << button[number][count % length];
			}
			count = 0;
			j = next;
		}
		cout<<endl;

	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;

int main() {
  string strs[9] = {{".,!? "}, {"abc"},  {"def"}, {"ghi"}, {"jkl"},
                    {"mno"},   {"pqrs"}, {"tuv"}, {"wxyz"}};
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string ans = "", sw;
    cin >> sw;
    int a = 0, b = 0;
    for (int j = 0; j < sw.size(); j++) {
      if (sw[j] == '0' && b >= 1) {
        ans += strs[a - 1][(b + strs[a - 1].size() - 1) % strs[a - 1].size()];
        a = 0, b = 0;
      }
      if (sw[j] == '0')
        continue;
      else {
        a = sw[j] - '0';
        b++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
#define rep(i,j) for(int i = 0; i < (j); i++)
int main(){
	int n;
	cin >> n;
	string c[] = {"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};	
	while(n--){
		string str;
		cin >> str;
		string ans = "";
		rep(i,str.size()){
			if(str[i] == '0')continue;
			int sub = i;
			while(str[i] == str[++sub]);
			ans += c[str[sub-1]-48][(sub-i-1)%c[str[sub-1]-48].size()];
			i = sub;
		}
		cout << ans << endl;
	}	
	return 0;
}

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

int main(){

  int n, cnt = 0, num = 0;
  string str, phone;

  cin >> n;

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









return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>

using namespace std;
typedef long long ll;

ll N;
vector<vector<char>> ans;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		char S[1030] = {};
		vector<char> vec;
		ans.push_back(vec);
		cin >> S;
		for (int j = 1; j < 1030; j++) {
			if (S[j] == 0)break;
			if (S[j] == '0' && S[j - 1] != '0') {
				for (int k = j - 1; k >= 0; k--) {
					if (S[k] != S[j - 1] || k == 0) {
						if (k == 0 && S[0] != '0')k--;
						switch (S[j - 1]) {
						case '1':
							switch ((j - k) % 5) {
							case 0:
								ans[i-1].push_back('?');
								break;
							case 1:
								ans[i-1].push_back(' ');
								break;
							case 2:
								ans[i-1].push_back('.');
								break;
							case 3:
								ans[i-1].push_back(',');
								break;
							case 4:
								ans[i-1].push_back('!');
							}
							break;
						case '2':
							ans[i-1].push_back('a' + (j - k - 2) % 3);
							break;
						case '3':
							ans[i-1].push_back('d' + (j - k - 2) % 3);
							break;
						case '4':
							ans[i-1].push_back('g' + (j - k - 2) % 3);
							break;
						case '5':
							ans[i-1].push_back('j' + (j - k - 2) % 3);
							break;
						case '6':
							ans[i-1].push_back('m' + (j - k - 2) % 3);
							break;
						case '7':
							ans[i-1].push_back('p' + (j - k - 2) % 4);
							break;
						case '8':
							ans[i-1].push_back('t' + (j - k - 2) % 3);
							break;
						case '9':
							ans[i-1].push_back('w' + (j - k - 2) % 4);
						}
						break;
					}
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < ans[i].size(); j++)cout << ans[i][j];
		cout << endl;
	}
	return 0;
}