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>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

char keitai[][6] =
{
	".,!? ",	
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz"
};

char out_keitai(int num, int count) {
	if (num == 1) {
		if (count%5 != 0) {
			return keitai[num-1][(count%5)-1];
		}else {
			return keitai[num-1][4];
		}
	}else if (num == 7 || num == 9) {
		if (count%4 != 0) {
			return keitai[num-1][(count%4)-1];
		}else {
			return keitai[num-1][3];
		}
	}else {
		if (count%3 != 0) {
			return keitai[num-1][(count%3)-1];
		}else {
			return keitai[num-1][2];
		}
	}
}
int main(void) {
	int n;
	char inp;
	std::string str;

	cin >> n;
	cin.ignore(2);

	for (int i = 0; i < n; i++) {
		getline(cin, str);
		int num;
		int count = 0;
		for (int j = 0; j < str.length() && j < 1024; j++) {
			std::string dstr;
			dstr = str.substr(j,1);
			num = atoi(dstr.c_str());
			if (num != 0) {
				count++;
				int seq = 1;
				int next_num;
				while (seq) {
					dstr = str.substr(j+1,1);
					next_num = atoi(dstr.c_str());
					if (num == next_num) {
						count++;
						j++;
					}else {
						seq = 0;
						cout << out_keitai(num,count);
						count = 0;
					}
				}	
			}
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

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

C++: #include <cstdio>
#include <iostream>
#include <cstdlib>

using namespace std;

char num1[5]={'.', ',', '!', '?', ' '};
char num2[]="abc", num3[]="def", num4[]="ghi", num5[]="jkl", num6[]="mno", num7[]="pqrs", num8[]="tuv", num9[]="wxyz";

char func(int x, int y);

int main()
{
	int n, ch;
	cin >> n;
	ch = getchar();
	for(int i = 0; i < n; i++){
		int c1, c2=-1, c3=0;
		char c;
		while(1){
			c1 = getchar();
			if(c1 == '\n'){
				cout << endl;
				break;
			} else if(c1 == '0'){
				if(c2 != -1){
					c = func(c2, c3);
					cout << c;
					c3 = 0;
					c2 = -1;
				}
			} else {
				if(c1 == c2) c3++;
				else {
					c1 = c1 - '0';
					c2 = c1;
					c3++;
				}
			}
		}
	}
	return 0;
}

char func(int x, int y)
{
	int z;
	if(x == 1) return num1[(y-1)%5];
	else if(x == 2) return num2[(y-1)%3];
	else if(x == 3) return num3[(y-1)%3];
	else if(x == 4) return num4[(y-1)%3];
	else if(x == 5) return num5[(y-1)%3];
	else if(x == 6) return num6[(y-1)%3];
	else if(x == 7) return num7[(y-1)%4];
	else if(x == 8) return num8[(y-1)%3];
	else return num9[(y-1)%4];
}

C++: #include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

char key[10][10] = {
  {},
  { 5, '.', ',', '!', '?', ' ' },
  { 3, 'a', 'b', 'c' },
  { 3, 'd', 'e', 'f' },
  { 3, 'g', 'h', 'i' },
  { 3, 'j', 'k', 'l' },
  { 3, 'm', 'n', 'o' },
  { 4, 'p', 'q', 'r', 's' },
  { 3, 't', 'u', 'v' },
  { 4, 'w', 'x', 'y', 'z' },
};

int main(void) {
  int n;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
	cin >> s;
	int k = 0, cnt = -1, d = 0;
	for (int j = 0; j < s.length(); j++) {
	  k = s[j] - '0';
	  if (k == 0) {
		if (d != 0) {
		  cout << key[d][cnt%key[d][0] + 1];
		}
		d = 0; cnt = -1;
	  }
	  else {
		d = k;
		cnt++;
	  }
	}
	cout << endl;
  }
}

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

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

	for(int j = 0; j < a; j++) {
		string str;
		cin >> str;
		string ret = "";

		int n = 0;
		char c;
		for(int i = 0; i < str.size(); i++) {
			switch(str[i]) {
				case '0':
					if(n)
						ret += c;
					n = 0;
					break;
				case '1':
					switch(n % 5) {
						case 0:
							c = '.';
							break;
						case 1:
							c = ',';
							break;
						case 2:
							c = '!';
							break;
						case 3:
							c = '?';
							break;
						case 4:
							c = ' ';
							break;
					}
					n++;
					break;
				case '2':
					c = 'a' + n % 3;
					n++;
					break;
				case '3':
					c = 'd' + n % 3;
					n++;
					break;
				case '4':
					c = 'g' + n % 3;
					n++;
					break;
				case '5':
					c = 'j' + n % 3;
					n++;
					break;
				case '6':
					c = 'm' + n % 3;
					n++;
					break;
				case '7':
					c = 'p' + n % 4;
					n++;
					break;
				case '8':
					c = 't' + n % 3;
					n++;
					break;
				case '9':
					c = 'w' + n % 4;
					n++;
					break;
			}
		}

		cout << ret << endl;
	}
	return 0;
}