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<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(){
	while(~scanf(" %s", _str)){
		str = _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 <iostream>
#include <string>

using namespace std;

int main(){
	char moji[10][6];
	strcpy(moji[1],".,!? ");
	strcpy(moji[2] ,"abc  ");
strcpy(moji[3], "def  ");
strcpy(moji[4],"ghi  ");
strcpy(moji[5],"jkl  ");
strcpy(moji[6],"mno  ");
strcpy(moji[7],"pqrs ");
strcpy(moji[8],"tuv  ");
strcpy(moji[9],"wxyz ");

	string str;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>str;
		int cnt=0;
		int num=0;
		for(int j=0;j<str.size();j++){
			if(str.at(j)=='0')continue;
			cnt=0;
			num=str.at(j)-'0';
			if(j==str.size()-2){
				cout<<moji[num][cnt];
				break;
			}

			while(str.at(j)==str.at(j+1)){
				cnt++;
				j++;
				if(j==str.size()-2){
					break;
				}
			}

			if(num==1){
				cnt%=5;
			}
			else if(num==7||num==9){
				cnt%=4;
			}
			else{
				cnt%=3;
			}

			cout<<moji[num][cnt];
		}
		cout<<endl;
	}
	return 0;
}

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

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

string solve(){
  string t = "";

  int key=0, cnt=0;
  for(int i=0; i<(int)s.size(); i++){
    int S = s[i] - '0';
    if(S==0){
      if(key!=0){
        cnt--;
        int len=a[key].size();
        t.push_back(a[key][cnt%len]);
      }
      cnt=key=0;
    } else if(key==S){
      cnt++;
    } else {
      key=S;
      cnt=1;
    }
  }
  return t;
}

int main(){
  int n;
  cin >> n;
  while(n--){
    cin >> s;
    cout << solve() << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <typeinfo>
#include <cxxabi.h>
#define type_name(class)  demangle((typeid(class)).name())
char* demangle(const char *demangle) {
    int status;
    return abi::__cxa_demangle(demangle, 0, 0, &status);
}

using namespace std;

class ButtonForwarder{
private:
	string m_chars;
	int m_nchars;
	unsigned int m_pos;
public:
	ButtonForwarder(){}
	ButtonForwarder(const string& str){
		m_chars = str;
		m_nchars = str.size();
		m_pos = -1;
	} 
	~ButtonForwarder(){}
	void push_button(){
		if(m_pos == m_nchars-1){
			m_pos = 0;
		}else{
			m_pos++;
		}
	}
	const string getCharacter(){
		// cout<<"In getCharacter() string is "<<m_chars<<endl;
		// cout<<"m_pos = "<<m_pos<<endl;
		return m_chars.substr(m_pos,1);
	}
	void reset(){m_pos=-1;}
};

class CellularKeyboard{
private:
	map<string, ButtonForwarder> m_buttons;
	string m_curButton;
	string result_temp;
public:
	CellularKeyboard(){m_curButton="";result_temp="";}
	void setStrings(string button, string chars){
		ButtonForwarder bf(chars);
		m_buttons[button] = bf;
	}
	string push(string button){
		// cout<<"push("<< button <<")"<<endl;
		//確定ボタン(キー0が押された場合)
		if(button == "0"){
			//何もボタンが押されていないときに確定ボタンを押すことはできるが、
			//その場合には何も文字は出力されない。
			if(m_curButton.length()==0){return string("");}
			
			// cout<<m_curButton<<endl;
			result_temp = m_buttons[m_curButton].getCharacter();
			m_buttons[m_curButton].reset();
			m_curButton = "";
			return result_temp;
		}
		m_curButton = button;
		m_buttons[button].push_button();
		// cout<<&(m_buttons[button])<<endl;
		// cout<<"Button"<<button<<" is "<<m_buttons[button].getCharacter()<<endl;
		return string("");
	}
};

int main() {
	// your code goes here
	CellularKeyboard kbd;
	kbd.setStrings(string("1"), string(".,!? "));
	kbd.setStrings(string("2"), string("abc"));
	kbd.setStrings(string("3"), string("def"));
	kbd.setStrings(string("4"), string("ghi"));
	kbd.setStrings(string("5"), string("jkl"));
	kbd.setStrings(string("6"), string("mno"));
	kbd.setStrings(string("7"), string("pqrs"));
	kbd.setStrings(string("8"), string("tuv"));
	kbd.setStrings(string("9"), string("wxyz"));
	
	int num;
	string input, decoded;
	cin>>num;
	for(int n=0;n<num;n++){
		cin>>input;
		decoded="";
		for(int i=0;i<input.length();i++){
			decoded += kbd.push(input.substr(i,1));
		}
		cout<<decoded<<endl;
	}
	
	// string input, decoded;
	// input ="000555555550000330000444000080000200004440000";
	// for(int i=0;i<input.length();i++){
	// 	// cout<<"char : "<<input.substr(i,1)<<" => "<<kbd.push(input.substr(i,1))<<endl;
	// 	decoded += kbd.push(input.substr(i,1));
	// }
	// cout<<decoded<<endl;
	return 0;
}

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

using namespace std;

#define all(i) i.begin(), i.end()
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
	int num = 0; cin >> num;
	string dat[12] = { "", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	rep(i, num)
	{
		string str; cin >> str;
		vector<int> hit(10, 0);
		rep(j, (int)str.size())
		{
			hit[str[j] - '0'] += 1;
			if (j == 0 || str[j - 1] == '0') {}
			else if (str[j] == '0')
			{
				int n = 0, tmp = str[j - 1] - '0';
				n = hit[tmp] % (int)dat[tmp].size();
				if (n == 0){ n = hit[tmp] + 1; }
				if (n >= 3 && (int)dat[tmp].size() == 3) { n -= 1; }
				printf("%c", dat[tmp][n - 1]);
				rep(i, 10){ hit[i] = 0; }
			}
		}
		printf("\n");
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

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


int main()
{

    int n;
    cin >> n;
    string s;
    rep(j,n)
    {
        cin >> s;
        int bnum = 0;
        int pushnum = 0;
        REP(s.size())
        {
            if(s[i] == '0' && pushnum > 0)
            {
                cout << button[bnum][(pushnum + button[bnum].size() - 1) % button[bnum].size()];
                pushnum = 0;
                bnum = 0;
                continue;
            }
            if(s[i] != '0'){ pushnum = (pushnum+1) ; bnum = s[i] - '0'; }
        }
        cout << endl;
    }
    return 0;
}