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 <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<cstring>
#include<cstdlib>
#include<cctype>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;


#define REP(i,n) for(int i= 0;i < n;i++)
	
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'}};
int a[] = {5,3,3,3,3,3,4,3,4};

int c;
char buf;
string str;
int n;
	
int main()
{
	n = 0;
	cin >> n;
	REP(i,n)
	{
		cin >> str;
		REP(j,str.size())
		{
			buf = str[j];
			if(buf == '0')continue;
			c = 0;j++;
			while(str[j] != '0')
			{
				c++;j++;
			}
			cout << mozi[(buf - '0')-1][c%a[buf - '0'-1]] ;
		}
		
		cout << endl;
		
	}
	
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	string but[10]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	
	for(int x=0;x<n;x++){
		string a;
		cin>>a;
	
	string ans="";
	int b=0,c=0;
		for(int i=0;i<a.size();i++){
			if(a[i]=='0'){
				if(b!=0){
				int num=(c+but[b].size()-1)%but[b].size();
				ans.push_back(but[b][num]);
				b=0,c=0;
				}
				}
			else{
				b=a[i]-'0';
				c++;
				}	
				
			}
			cout<<ans<<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<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

    map<char,string> m;
    m['1'] = ".,!? ";
    m['2'] = "abc";
    m['3'] = "def";
    m['4'] = "ghi";
    m['5'] = "jkl";
    m['6'] = "mno";
    m['7'] = "pqrs";
    m['8'] = "tuv";
    m['9'] = "wxyz";

    rep(i,n) {
        string s;
        cin >> s;
        
        stringstream ss;
        int cnt = -1,id = -1;
        rep(j,s.size()) {
            if(s[j] == '0') {
                if(id != -1) {
                    cnt %= m['0'+id].size();
                    ss << m['0'+id][cnt];

                    cnt = -1;
                    id = -1;
                }
            }
            else {
                cnt++;
                id = (int)(s[j]-'0');
            }
        }

        cout << ss.str() << endl;
        
    }
    
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){   
  char m[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 a,count=0,c[100],d,e;
  char b[100][1024];
  cin>>a;
  for(int i=0;i<a;i++){
    scanf("%s",b[i]);
    c[i]=strlen(b[i]);
    for(int j=0;j<c[i];j++){
      if(b[i][j]!='0')count++;
      else{
	if(b[i][j-1]!=0){
	  d=(int)(b[i][j-1])-48;

	  if(d==1){
	    e=count%5;
	    if(e!=0)
	      cout<<m[d-1][e-1];
	    else cout<<m[d-1][3];
	  }
	  else if(d==7 || d==9){
	    e=count%4;
	    if(e!=0)
	      cout<<m[d-1][e-1];
	    else cout<<m[d-1][3];
	  }
	  else {
	    e=count%3;
	    if(e!=0)
	      cout<<m[d-1][e-1];
	    else cout<<m[d-1][2];
	  }
	  count=0;
	}
      }
    }
    cout<<endl;
  }
  return 0;
}