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

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

  string rule[10] = {"", ".,!? ", "abc", "def", "ghi",
                     "jkl","mno", "pqrs", "tuv", "wxyz"};
  
  for(int i=0; i<n; i++){
    string s;
    getline(cin, s);

    string ans = "", temp = "";
    int before = 0, index = 0;
    for(int j=0; j<s.size(); j+=2){
      if(s[j] - '0' == 0){
        ans += temp;
        temp = "";
        index = 0;
      }else if(before == s[j] - '0'){
        temp = rule[before][index];
        index = (index+1)%rule[before].size();
      }else{
        temp = rule[s[j] - '0'][0];
        index = 1;
      }
      before = s[j] - '0';
    }

    cout << ans << endl;
  }
  
  return 0;
}

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

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

using namespace std;

const vector<string> keys = {
    "",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};

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

    while (C-- > 0) {
        string s;
        cin >> s;

        int pos = 0;
        string res = "";
        for (int i = 0; i < s.length() - 1; i++) {
            int k = stoi(s.substr(i, 1));
            if (s[i] == s[i + 1] && k != 0) {
                pos = (pos + 1) % keys[k].length();
            } else {
                res += keys[k][pos];
                pos = 0;
            }
        }

        cout << res << endl;
    }
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v),end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

vector<vector<char> > v={
    {'.',',','!','?',' '},
    {'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 main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    while(n--)
    {
        string s; cin>>s;
        for(int i=0;i<s.size();i++){
            if(s[i]=='0') continue;
            int x=s[i]-'0'-1;
            int j=i;
            while(j<s.size() && s[i]==s[j]) j++;
            int y=(j-i-1)%v[x].size();
            cout<<v[x][y];
            i=j;
        }
        cout<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
vector<vector<char> > phone = {
    {},
    {' ', '.', ',', '!', '?'},
    {'c', 'a', 'b'},
    {'f', 'd', 'e'},
    {'i', 'g', 'h'},
    {'l', 'j', 'k'},
    {'o', 'm', 'n'},
    {'s', 'p', 'q', 'r'},
    {'v', 't', 'u'},
    {'z', 'w', 'x', 'y'}
};

int main() {
    int n; cin >> n;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        int k = 0, kl = 0;
        for (char c : s) {
            if (c - '0' == 0) {
                if (kl == 0) continue;
                cout << phone[kl][k];
                k = 0;
                kl = 0;
            } else {
                kl = c - '0';
                k = (k+1) % phone[kl].size();
            }
        }
        cout << endl;
    }
    return 0;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)


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

void display(int num,int cnt){
	switch(num){
		case 1: cout<<o[cnt%5]; break;
		case 2: cout<<a[cnt%3]; break;
		case 3: cout<<d[cnt%3]; break;
		case 4: cout<<g[cnt%3]; break;
		case 5: cout<<j[cnt%3]; break;
		case 6: cout<<m[cnt%3]; break;
		case 7: cout<<p[cnt%4]; break;
		case 8: cout<<t[cnt%3]; break;
		case 9: cout<<w[cnt%4]; break;
	}
}
	
int main(void){
	int num;
	cin>>num;
	while(num--){
		string n;
		cin>>n;
		int cnt = 0;
		int num = - 1;
		rep(i,n.size()){
			if(n[i]=='0'){
//				cout<<cnt;
				display(num,cnt);
				cnt = 0;
			}
			if(n[i]-'0'==num && n[i]!='0')cnt++;
			
			num=n[i]-'0';
		}
		cout<<endl;
	}
}

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

int main(void){
	string b[9] = {
		".,!? ",
		"abc",
		"def",
		"ghi",
		"jkl",
		"mno",
		"pqrs",
		"tuv",
		"wxyz",
	};

	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s; //char s[100];
		cin>>s;
		int len = s.length();

		//OÌ¶ before
		//beforeª½ñ±¢½© count
		char before = '0';
		int count = 0;
		for(int i=0;i<len;i++){
			if(s[i] == '0' && before != '0'){
				cout<<b[before - '1'][(count - 1) % b[before - '1'].length()];
				before = '0';
				count = 0;
			}
			else if('1' <= s[i] && s[i] <= '9'){
				before = s[i];
				count++;
			}
		}
		cout<<endl;
	}

	return 0;
}