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;
	cin>>n;
	for(int i=0;i<n;i++){
		string str,one=".,!? ",ans;
		cin>>str;
		for(int j=0,co=0,num=0;j<=str.size();j++){
			if(num==str[j]-'0')co++;
			else{
				if(num==1)ans+=one[co%5];
				else if(num==7)ans+=co%4+'p';
				else if(num==8)ans+=co%3+'t';
				else if(num==9)ans+=co%4+'w';
				else if(num>1)ans+=co%3+'a'+3*(num-2);
				co=0;
				num=str[j]-'0';
			}
		}
		cout<<ans<<endl;
	}
}

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

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

using namespace std;

int main(){
    string keitai[10] =
        {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    string str;
    int n; cin >> n;
    REP(k,n){
        cin >> str;
        int len = str.size();
        int cur=0, cnt=0;
        int tmp;
        REP(i,len){
            if(str[i]=='0'){ //00???????????¨???cnt=0
                if(cnt!=0){
                    if(cnt % keitai[cnt].size()==0){
                        tmp = keitai[cnt].size() - 1;
                    }else{
                        tmp = cnt % keitai[cnt].size() - 1;
                    }
                    cout << keitai[cur][tmp];
                }
                cur=0; cnt=0;
            }else{ //str[i]!='0'
                if(cur==0){//0??\?????\????????????
                    cur = str[i] - '0';
                    cnt++;
                }else{
                    cnt++;
                }
            }
        }
        cout << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
 
int main() {
    int n,m,a[10] = {0,0,0,0,0,0,0,0,0,0};
    string s,t;
    string s1(".,!? ");
    string s2("abc");
    string s3("def");
    string s4("ghi");
    string s5("jkl");
    string s6("mno");
    string s7("pqrs");
    string s8("tuv");
    string s9("wxyz");
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> s;
        for(int j = 0;j < s.size();j++){
            if(s[j] == '0' && a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9] == 0)continue;
            else if(s[j] == '1'){
                t = s1;
                m = 1;
                a[1]++;
            }else if(s[j] == '2'){
                t = s2;
                m = 2;
                a[2]++;
            }else if(s[j] == '3'){
                t = s3;
                m = 3;
                a[3]++;
            }else if(s[j] == '4'){
                t = s4;
                m = 4;
                a[4]++;
            }else if(s[j] == '5'){
                t = s5;
                m = 5;
                a[5]++;
            }else if(s[j] == '6'){
                t = s6;
                m = 6;
                a[6]++;
            }else if(s[j] == '7'){
                t = s7;
                m = 7;
                a[7]++;
            }else if(s[j] == '8'){
                t = s8;
                m = 8;
                a[8]++;
            }else if(s[j] == '9'){
                t = s9;
                m = 9;
                a[9]++;
            }
            else if(s[j] == '0' && a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9] != 0){
                if(m == 1){
                    cout << t[(a[m]-1)%5];
                    a[m] = 0;
                }
                else if(m == 7 || m == 9){
                    cout << t[(a[m]-1)%4];
                    a[m] = 0;
                }
                else{
                    cout << t[(a[m]-1)%3];
                    a[m] = 0;
                }
            }
        }
        cout << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;int main(){int n,b[]={1,5,3,3,3,3,3,4,3,4},m,i;string s;char t[20][6]={" ",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};cin>>n;while(cin>>s){for(i=m=0;i<s.size();i++)if(s[i]=='0'){if(m)cout<<t[s[i-1]-'0'][(m-1)%b[s[i-1]-'0']];m=0;}else
m++;cout<<endl;}return 0;}

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

char mes(char c){
    int n = c -'0';
    if(n==2)return 'a';
    else if(n==3)return 'd';
    else if(n==4)return 'g';
    else if(n==5)return 'j';
    else if(n==6)return 'm';
    else if(n==7)return 'p';
    else if(n==8)return 't';
    else return 'w';
}


int main(){
    long long n;
    cin >> n;
    for(int i=0;i<n;i++){
        string str;
        cin >> str;
        int cou = 1;
        for(int j=1;j<str.size();j++){
           if(str[j]=='0' && str[j-1]!='0'){
                if(str[j-1]!='0'){
                    if(cou)cou--;
                    if(str[j-1]!='1'){
                        char a = mes(str[j-1]);
                        if(str[j-1]=='7'||str[j-1]=='9')printf("%c",a + (cou)%4);
                        else printf("%c",a+cou%3);
                    }else{
                       cou%=5;
                        if(!cou)cout << ".";
                        else if(cou==1)cout << ",";
                        else if(cou==2)cout << "!";
                        else if(cou==3)cout << "?";
                        else cout << " ";
                    }
                }
                cou = 0;
           }else{
               cou++;
           }
        }
        cout << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1080], b[1080];
int n, m;

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

char _str[10800];
void output(int val, int cnt){
	if(val == 0)return;
	cout << button[val][(cnt-1) % button[val].size()];
}


int main(){
	int q;
	cin >> q;
	while(q--){
		cin >> str;
		int val = 0;
		int cnt = 0;
		for(int i = 0;i < str.size();i++){
			if(str[i] == '0'){
				output(val, cnt);
				val = cnt = 0;
			}
			else{
				val = str[i] - '0';
				cnt++;
			}
		}
		output(val, cnt);
		cout << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  string in;
  char list[9][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','/','/'}
  };
  
  int x=-1,y=-1;
  
  cin >>N;
  
  for(int i=0 ; i < N ; i++){
    
    cin >>in;
    
    for(int j=0 ; j < (int)in.size() ; j++){
      
      char in_one=in[j];
      int num=atoi(&in_one);

      if(num == 0){
	if(y != -1)cout <<list[y][x];
	y=-1;
	x=-1;
      }else{
	x++;
	if(list[y][x] == '/')x=0;
	y=num-1;
      }
      
    }
    cout <<endl;
    
  }
  
  return 0;
}