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>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)

using namespace std;

int main()
{
  char keitai[10][5] = {{'*', '*', '*', '*', '*'},
                        {'.', ',', '!', '?', ' '},
                        {'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', '*'},
  };
  string s;
  int x , c;
  char p;
  int n;
  cin >> n;
  cin.ignore();
  REP(k, n){
    getline(cin, s);
    x = c = 0;
    p = '*';
    REP(i, s.size()){
      int j;
      j = s[i] - '0';
      if(j){
        if(x == j){
          if(keitai[j][c + 1] == '*'){
            c = 0;
            p = keitai[j][c];
          }else{
            c++;
            p = keitai[j][c];
          }
        }else{
          c = 0;
          p = keitai[j][c];
        }
      }else{
        if(p != '*')
          cout << p;
        p = '*';
      }
      x = j;
    }
    cout << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s[]={"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  int n; cin>>n;
  while(n--){
    string t,ans;
    cin >> t;
    int cnt=-1,num=0;
    for(int i=0;i<t.size();++i){
      if(t[i]=='0'){
        if(cnt!=-1){
          ans+=s[num][cnt%s[num].size()];
          cnt=-1;
        }
      }else{
        num=t[i]-'0';
        cnt++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;

signed main(){
  vector<string> str={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  int n;
  cin>>n;
  while(n--){
    string s;
    cin>>s;
    vector<pair<int,int>> p;
    REP(i,s.size()){
      int c=s[i]-'0';
      if(c==0)continue;
      int tmp=-1;
      while(s[i]!='0'){
        tmp++;
        i++;
      }
      p.PB(MP(c-1,tmp));
    }
    REP(i,p.size()){
      int f=p[i].FR;int sc=p[i].SC;
      if(f==0)cout<<str[0][sc%5];
      else if(f==6||f==8)cout<<str[f][sc%4];
      else cout<<str[f][sc%3];
    }
    cout<<endl;
   }
  return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<char> button1={'.',',','!','?',' '};
    int n; cin >> n;
    for (int i=0;i<n;++i){
        string s,ans=""; cin >> s;
        int cnt=-1;
        for (int j=0;j<s.size();++j){
            if (s[j]!='0'){++cnt; continue;}
            if (j==0||s[j-1]=='0') continue;
            int x=s[j-1]-'0';
            if (x==1) ans+=button1[cnt%5];
            else if (x==7) ans+='p'+cnt%4;
            else if (x==8) ans+='t'+cnt%3;
            else if (x==9) ans+='w'+cnt%4;
            else ans+='a'+((x-2)*3+cnt%3);
            cnt=-1;
        }
        cout << ans << endl;
    }
}

C++: #include<stdio.h>
#include<string.h>
main(){
    int N;
    char S[77];
    scanf("%d",&N);
    char str[][6] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    for(int i = 0;i < N;i++){
        scanf("%s",S);
        int num = 0;//?????¨??\??????????????????
        int count = 0;
        for(int j = 0;j < strlen(S);j++){
            if(S[j] != '0'){num = S[j] - '0';}
            if(S[j] == '0' && num == 0){continue;}
            if(S[j] == S[j+1]){
                count++;
                continue;
            }
            printf("%c",str[num-1][count%(strlen(str[num-1]))]);
            count = 0;
            num = 0;
        }
        printf("\n");
    }
}

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

using namespace std;

vector<string> V;

int main(){
    V.push_back("");
    V.push_back(".,!? ");
    V.push_back("abc");
    V.push_back("def");
    V.push_back("ghi");
    V.push_back("jkl");
    V.push_back("mno");
    V.push_back("pqrs");
    V.push_back("tuv");
    V.push_back("wxyz");

    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string out = "";
        string inp = "";
        cin >> inp;
        char now;
        int kai;
        now = '0';kai = 0;
        for(int j=0;j<inp.length();j++){
            if(inp[j] == '0'){
                if(kai != 0){
                    kai--;
                    out += V[now-'0'][kai%(V[now-'0'].length())];
                }
                now = inp[j];
                kai = 0;
                continue;
            }
            now = inp[j];
            kai++;
        }
        cout << out << endl;
    }
}

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

int main(){
  vector<string> num = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

  int n;
  cin >> n;
  string ans;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    
    ans = "";
    int j = 0;
    stack<int> st;
    for(int j = 0; j < s.length(); j++){
      if(s[j] == '0'){
        if(st.empty())continue;
        ans += num[st.top()][(st.size() - 1) % 3];

        while(!st.empty())st.pop();
      }else{
        st.push(s[j] - '0');
      }
    }
    cout << ans << endl;
  }
}

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 tmp = str[j - 1] - '0', n = hit[tmp];
				while (1)
				{
					if (n <= (int)dat[tmp].size()) { break; }
					n -= (int)dat[tmp].size();
				}
				/*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;
}