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>
using namespace std;

int main()
{
	int N;
	string str,res;
	cin >> N;
	for (int i = 0; i < N; i++) {
		res = "";
		cin >> str;
		char ch = 0;
		int inc = 0;
		for (int j = 0; j < str.length();j++) {
			switch (str[j]) {
			case '0':
				if (ch) {
					if (ch == '.') {
						if (inc % 5 == 0) {
							res += '.';
						}else if (inc % 5 == 1) {
							res += ',';
						}
						else if (inc % 5 == 2) {
							res += '!';
						}
						else if (inc % 5 == 3) {
							res += '?';
						}
						else if (inc % 5 == 4) {
							res += ' ';
						}
					} else if(ch == 'p' || ch == 'w')
						res += (char)(ch + (inc % 4));
					else
						res += (char)(ch + (inc % 3));
				}
				ch = 0;
				inc = 0;
				break;
			case '1':
				if (ch == '.')
					inc++;
				else
					ch = '.';
				break;
			case '2':
				if (ch == 'a')
					inc++;
				else
					ch = 'a';
				break;
			case '3':
				if (ch == 'd')
					inc++;
				else
					ch = 'd';
				break;
			case '4':
				if (ch == 'g')
					inc++;
				else
					ch = 'g';
				break;
			case '5':
				if (ch == 'j')
					inc++;
				else
					ch = 'j';
				break;
			case '6':
				if (ch == 'm')
					inc++;
				else
					ch = 'm';
				break;
			case '7':
				if (ch == 'p')
					inc++;
				else
					ch = 'p';
				break;
			case '8':
				if (ch == 't')
					inc++;
				else
					ch = 't';
				break;
			case '9':
				if (ch == 'w')
					inc++;
				else
					ch = 'w';
				break;
			}
		}
		if(ch) {
			if (ch == '.') {
				if (inc % 5 == 0) {
					res += '.';
				}
				else if (inc % 5 == 1) {
					res += ',';
				}
				else if (inc % 5 == 2) {
					res += '!';
				}
				else if (inc % 5 == 3) {
					res += '?';
				}
				else if (inc % 5 == 4) {
					res += ' ';
				}
			}
			else if (ch == 'p' || ch == 'w')
				res += (char)(ch + (inc % 4));
			else
				res += (char)(ch + (inc % 3));
		}
		cout << res << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
string kei[] = {".,!? ","abc","def","ghi",
		"jkl","mno","pqrs","tuv","wxyz",};

int main(){
  string str;
  int n;
  cin >> n;
  while(n--){
    cin >> str;
    int cnt = 0;
    for(int i = 0 ; i < str.size()-1 ; i++ ){
      if(str[i] == str[i+1] && str[i] != '0')cnt++;
      if(str[i] == '0' && str[i+1] == '0')continue;
      if(str[i]!='0' && str[i+1] == '0'){
	cout << kei[(str[i]-'0')-1][cnt%(kei[(str[i]-'0')-1].size())];  
	cnt = 0;
      }
    }
    cout << endl;
  }
}

C++: #include <iostream>
#include <string.h>
using namespace std;
int main(){
  int n,i,j,len,count,which,flag;
  char in[1025];
  char data[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'}
  };
  cin >> n;
  for(i=0;i<n;i++){
    cin >> in;
    len=strlen(in);
    count=-1;
    which=0;
    for(j=0;j<len;j++){
      flag=0;
      if(in[j]=='1') which=1;
      else if(in[j]=='2') which=2;
      else if(in[j]=='3') which=3;
      else if(in[j]=='4') which=4;
      else if(in[j]=='5') which=5;
      else if(in[j]=='6') which=6;
      else if(in[j]=='7') which=7;
      else if(in[j]=='8') which=8;
      else if(in[j]=='9') which=9;
      else{
        if(which==0) continue;
	if(which==1) count%=5;
	else if(which==2||which==3||which==4||which==5||which==6||which==8) count%=3;
	else if(which==7||which==9) count%=4;
	cout << data[which][count];
	flag=1;
        count=-1;
      }
      if(flag==0) count++;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
vector <char> v;
vector<string>ansl;
string s;
string ans;
int main(){
  int N;
  char mozi[][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'}};

  cin >>N;

  for(int i=0;i<N;i++){
    string ans;
    int ind = 0;
    cin >>s;
    for(ind = 0;ind<(int)s.size();ind++){
      int num = 0;

      while(s[ind] != '0'){
        num++;
        ind++;
      }
      int indx = stoi(&(s[ind-1]))-1;

      if(s[ind-1] == '1'){
        ans = ans + mozi[0][num%5];
      }else if((s[ind-1] == '4')||(s[ind] == '9')){
        ans = ans + mozi[indx][num%4];
      }else{
        ans = ans + mozi[indx][num%3];
      }
    }
    ansl.push_back(ans);
  }
  for (int i = 0;i<N;i++){
    cout <<ansl[i]<<endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	char a[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 n,c=0,d=0;
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;d=c=0;
			for(int j=0;j<s.size();j++){
				if(s[j]=='0'&&c>0){
					if(s[j-1]=='1')d=(c-1)%5;
					else if(s[j-1]=='7'||s[j-1]=='9')d=(c-1)%4;
					else d=(c-1)%3;
					cout<<a[(int)(s[j-1]-'0')-1][d];
				c=0;
				}
				else if(s[j]=='0'&&s[j-1]=='0')c=0;
				else c++;
				}
				cout<<'\n';
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
char in[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(){
  int n;
  cin>>n;
  rep(j,n){
    string s;
    cin>>s;
    int i=0;
    while(i!=s.size()){
      int co=0;
      while(s[i]!='0'){
	co++;
	i++;
      }
      //cout<<co<<endl;
      if(co)cout<<in[s[i-1]-'0'-1][(co-1)%in1[s[i-1]-'0'-1]];
      i++;
    }
    cout<<endl;
  }
}

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

int main(int argc, char *argv[])
{
    string map[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno",
        "pqrs", "tuv", "wxyz"};
    string line;
    int n, cnt, num;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> line;
        cnt = 0;
        for (int j = 0; j < line.length(); ++j) {
            if (line[j] == '0') {
                if (j == 0 || line[j - 1] == '0')
                    continue;
                num = line[j - 1] - '0';
                cout << map[num][(cnt - 1) % map[num].length()];
                cnt = 0;
            } else if (line[j] != '0') {
                cnt++;
            }
        }
        cout << endl;
    }
    return 0;
}