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;

#define int				long long
#define FOR( i, m, n )	for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )		FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )		(a).begin(), (a).end()
#define MP				make_pair

typedef pair<int, int> P;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
	int n, cnt;
	char ch1, ch2;
	char number[10][6] = {
		{},
		{ 5, '.', ',', '!', '?', ' ' },
		{ 3, 'a', 'b', 'c' },
		{ 3, 'd', 'e', 'f' },
		{ 3, 'g', 'h', 'i' },
		{ 3, 'j', 'k', 'l' },
		{ 3, 'm', 'n', 'o' },
		{ 4, 'p', 'q', 'r', 's' },
		{ 3, 't', 'u', 'v' },
		{ 4, 'w', 'x', 'y', 'z' }
	};

	cin >> n; cin.get( ch1 );
  REP( i, n ){
    while( cin.get( ch1 ), ch1 != '\n' ){
      cnt = 0;
      while( cin.get( ch2 ), ch2 == ch1 ) cnt++;

      if( ch2 == '0' ){
        cout << number[ch1 - '0'][cnt % number[ch1 - '0'][0] + 1];
      }else{
        cin.putback( ch2 );
      }
    }
    cout << endl;
  }

}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  char button[11][11]={
    {'.',',','!','?',' '},
    {'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;
  cin>>n;
  for(int j=0;j<n;j++){
    string s;
    cin>>s;
    int cnt=0,index=-1;
    for(int i=0;i<s.size();i++){
      if(s[i]=='0'){
        if(index==-1){
          cnt=0;
          continue;
        }
        cnt--;
        cnt%=strlen(button[index]);
        cout<<button[index][cnt]<<flush;
        cnt=0;
        index=-1;
      }else{
        cnt++;
        index=s[i]-'1';
      }
    }
    cout<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	cin>>n;
	string str,num[10]={"0","1","2","3","4","5","6","7","8","9"};
	string s[10]={" ",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	for(int i=0;i<n;i++){
		cin>>str;
		for(int j=0;j<str.size();j++){
			for(int k=1;k<=9;k++){
				if(num[k][0]==str[j]){
					int cnt=-1;
					while(str[j]!='0'){
						cnt++;
						j++;
					}
					string S=s[k];
					cout<<S[cnt%S.size()];
				}
			}
		}
		cout<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

string keitai[]{".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
int main(){
	string s;
	while(cin>>s){
		int cnt=0;
		string ans;
		rep(i,s.size()){
			if(s[i]=='0'){
				if(cnt)ans+=keitai[s[i-1]-'1'][(cnt-1)%keitai[s[i-1]-'1'].size()];
				cnt=0;
			}
			else cnt++;
		}
		if(ans!="")cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <queue>

#define MAX 100005
#define ll long long int
using namespace std;

int main(void)
{
	string s; // input
	int n;
	int i, j;

	string an;
	int zero = 0; // zero?????´???

	vector <string> ans;
	queue <char> qu;

	char temp;
	int count = 0;
	char tempm; //mozi???????????????????´?




	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> an;

		for (j = 0; j < an.size(); j++) { //qu?????°?????????
			qu.push(an[j]);

		}



		
		while (qu.empty() == 0) {
			count = 0;
			tempm = 'n'; //?????????


			while (1) {
				temp = qu.front();
				if (temp != '0') {
					tempm = temp;
					count++;
					qu.pop();
				}
				else { //0?????£??????
					qu.pop();
					break;
				}


			}



			if (tempm == '1') { // 1?????¨???
				count = count % 5;

				switch (count) {
				case 1:
					s.push_back('.');
					break;
				case 2:
					s.push_back(',');
					break;
				case 3:
					s.push_back('!');
					break;
				case 4:
					s.push_back('?');
					break;
				case 0:
					s.push_back(' ');
					break;
				}
			}
			else if (tempm == '2') { // 2
				count = count % 3;
				switch (count) {
				case 1:
					s.push_back('a');
					break;
				case 2:
					s.push_back('b');
					break;
				case 0:
					s.push_back('c');
					break;

				}
			}
			else if (tempm == '3') { // 3
				count = count % 3;
				switch (count) {
				case 1:
					s.push_back('d');
					break;
				case 2:
					s.push_back('e');
					break;
				case 0:
					s.push_back('f');
					break;

				}
			}
			else if (tempm == '4') { // 4
				count = count % 3;
				switch (count) {
				case 1:
					s.push_back('g');
					break;
				case 2:
					s.push_back('h');
					break;
				case 0:
					s.push_back('i');
					break;

				}
			}
			else if (tempm == '5') { // 5
				count = count % 3;
				switch (count) {
				case 1:
					s.push_back('j');
					break;
				case 2:
					s.push_back('k');
					break;
				case 0:
					s.push_back('l');
					break;

				}
			}
			else if (tempm == '6') { // 6
				count = count % 3;
				switch (count) {
				case 1:
					s.push_back('m');
					break;
				case 2:
					s.push_back('n');
					break;
				case 0:
					s.push_back('o');
					break;

				}
			}
			else if (tempm == '7') { // 7
				count = count % 4;
				switch (count) {
				case 1:
					s.push_back('p');
					break;
				case 2:
					s.push_back('q');
					break;
				case 3:
					s.push_back('r');
					break;
				case 0:
					s.push_back('s');
					break;

				}
			}
			else if (tempm == '8') { // 8
				count = count % 3;
				switch (count) {
				case 1:
					s.push_back('t');
					break;
				case 2:
					s.push_back('u');
					break;
				case 0:
					s.push_back('v');
					break;

				}
			}
			else if (tempm == '9') { // 9
				count = count % 3;
				switch (count) {
				case 1:
					s.push_back('w');
					break;
				case 2:
					s.push_back('x');
					break;
				case 3:
					s.push_back('y');
					break;
				case 0:
					s.push_back('z');

				}
			}




		}

		ans.push_back(s);
		



		s.clear();
	}

	for (i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}


	return (0);
}

C++: #include <cstdio>

const char *TABLE[] = {
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz"
};

int main(){
	int N;
	scanf("%d", &N);
	while(N--){
		char input[1025];
		scanf("%s", input);
		int key = -1, idx = -1;
		for(char *p = input; *p != '\0'; p++){
			int k = *p - '0' - 1;
			if(k < 0){
				if(idx >= 0 && key >= 0){
					putc(TABLE[key][idx], stdout);
					idx = -1;
				}
			}else{
				if(k != key){ idx = -1; }
				if(TABLE[k][++idx] == '\0'){ idx = 0; }
			}
			key = k;
		}
		puts("");
	}
	return 0;
}