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, c;
	string key[] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	string input;
	char p;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> input;
		c = 0;
		p = '0';
		for (int j = 0; j < input.size(); j++) {
			if (input[j] == '0' && p != '0') {
				cout << key[p - '0'][(c - 1) % key[p - '0'].size()] << endl;
				c = 0;
			} else if (input[j] == p) {
				c++;
			} else {
				c = 1;
			}
			p = input[j];
		}
	}
	
	return 0;
}

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

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

int main(){
  int T;
  cin >> T;
  while(T--){
    string ans = "";
    string s;
    cin >> s;
    
    int tmp;
    for(int i = 0 ; i < s.size() ;i++){
      int cnt = 0;
      tmp = s[i]-'0';
      if(tmp == 0) continue;
      while(1){
	if(s[i] != s[i+1]) break;
	cnt++, i++;
	if(button[tmp].size() == cnt) cnt = 0;
      }
      ans += button[tmp][cnt];
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>

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

int main(){
    int N;
    std::cin >> N;

    for(;N--;){
        std::string S;
        std::cin >> S;

        int key = -1, index = -1;
        std::string T = "";
        for(char c : S){
            if(c == '0'){
                if(~key){
                    T += table[key][index];
                    key = -1;
                    index = -1;
                }
            }else{
                if(!~key){
                    key = c - '0';
                    index = 0;
                }else{
                    index = (index+1) % table[key].size();
                }
            }
        }

        std::cout << T << std::endl;
    }
}

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

using namespace std;

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

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

  while (N--) {
    string str;
    cin >> str;

    int s = 0, cnt = -1;
    for (int i=0; i<str.size(); i++) {
      int d = str[i] - '0';
      if (d == 0) {
        if (s != 0) { cout << m[s][ (cnt % m[s][0]) + 1 ]; }
        s = 0; cnt = -1;
      } else {
        s = d;
        cnt++;
      }
    }

    cout << endl;
  }

  return 0;
}

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;}
//-----------------------------------------------------------------------

string table[10]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

int n; cin>>n;
while(n--)
{
    string s; cin>>s;
    int cnt=0,idx;
    REP(i,s.size()){
        if(s[i]!='0'){
            cnt++;
            idx=s[i]-'0';
        } else{
            if(cnt>0) cout<<table[idx][(cnt-1)%table[idx].size()];
            cnt=0;
        }
    }
    cout<<endl;
}
}

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

int main(){
  string p[9]={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  string s;
  int n;
  cin>>n;
  while(n--){
    cin>>s;
    for(int i=0;i<(int)s.size();i++)
      if(s[i]=='0') s[i]=' ';
    stringstream ss(s);
    while(ss>>s){
      cout<<p[s[0]-'1'][(s.size()-1) % p[s[0]-'1'].size()];
    }
    cout<<endl;
  }

  return 0;
}

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

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

int main(){
	int n;
	int code;
	int num;
	char key[11][7] = {
			{},
			{'.',',','!','?',' '},
			{'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'},
	};

	std::cin >> n;
	std::string str;

	rep(i,n){
		code = 0;
		num = 0;
		std::cin >> str;
		rep(j,(int)str.size()){
			if(str[j] != '0'){
				num++;
			}else{
				if(j > 0 && str[j-1] != '0'){
					code = str[j-1]-'0';
					if(code == 1){
						std::cout << key[code][(num-1)%5] << std::flush;
					}else if(code == 7 || code == 9){
						std::cout << key[code][(num-1)%4] << std::flush;
					}else{
						std::cout << key[code][(num-1)%3] << std::flush;
					}
					code = 0;
					num = 0;
				}
			}
		}
		std::cout << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    char ans[][10] = {
        {},
        {'.',',','!','?',' '},
        {'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;
    rep(i,n){
        string s(100000,0);
        cin >> s;
        int temp = 0;
        int counter =-1 ;
        for(int k = 0;k<s.size();k++){
            int now = int(s[k]-48);
            if(k == 0){temp = now;counter++;}
            else if(now != 0){
                temp = now;counter++;}
            if(now == 0){
                if(temp  == 9 || temp == 7)
                    counter%=4;
                else if(temp != 1&& temp != 7 && temp!= 9)
                    counter%=3;
                else if(temp == 1)
                    counter %=5;
                cout << ans[temp][counter];
                temp = 0;counter =-1;;
            }
        }
        cout << endl;
    }
}