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>

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

void solve(void){

	int m;					//文字列の行数
	std::string sl;		//文字列格納用ストリング型変数

	char c[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'},
	};

	std::cin >> m;
	while(m--){

		int t = 0;

		std::cin >> sl;

		rep(i,sl.size()-1){
			if(sl[i] == sl[i+1]){
				t++;
			}else{
				if(sl[i]=='7' || sl[i]=='9'){
					t %= 4;
				}
				else if(sl[i]=='1'){
					t %= 5;
				}else{
					t %= 3;
				}
				if(sl[i] != '0'){
					std::cout << c[sl[i]-'0'][t];
				}
				t = 0;
			}
		}
		std::cout << std::endl;
	}
}

int main(void){

	solve();

	return 0;
}

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

int main(){
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
  string s;
  cin>>s;
  char u=' ', b=0;
  char p[]={' ','.', 'a','d','g','j','m','p','t','w'};
  string t="";
  for(int i=0; i<s.size();i++) {
    int x=s[i]-'0';
    if (x==0) {
      if (b>0) {
      if (u=='.') {
        char f[]={'.',',','!','?', ' '};
        t+=string(1, f[b-1]);
      } else {
        t+=string(1, (char)(u+b-1));
      }
      b = 0;
      }
    } else {
      u=p[x];
      b++;
      if (x==7||x==9) {
        if (b==5) b=1;
      } else if (x==1) {
        if (b==6) b=1;
      } else if (b==4) b=1;
    }
  }
  cout<<t<<endl;
}
  return 0;
}

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>
using namespace std;
int main(){
  string s[9];
  s[0]=".,!?S";
  s[1]="abc";
  s[2]="def";
  s[3]="ghi";
  s[4]="jkl";
  s[5]="mno";
  s[6]="pqrs";
  s[7]="tuv";
  s[8]="wxyz";
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string t;
    cin>>t;
    int c=0;
    for(int j=1;j<t.size();j++){
      if(t[j]=='0'&&t[j-1]!='0'){
	if(s[t[j-1]-'1'][(j-c-1)%s[t[j-1]-'1'].size()]=='S')cout<<" ";
	else cout<<s[t[j-1]-'1'][(j-c-1)%s[t[j-1]-'1'].size()];
	c=j+1;
      }
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int check(int num,char c){
  if(c == '1')return num%5;
  if(c == '7' || c == '9')return num%4;
  else return num%3;
}

int main(){
  int n,i,j;
  string s;
  char b[10][5];
  char c = 'a';
  b[1][0]='.';
  b[1][1]=',';
  b[1][2]='!';
  b[1][3]='?';
  b[1][4]=' ';
  for(i=2;i<10;i++){
    for(j=0;j<3;j++){
      b[i][j]=c;
      c++;
    }
    if(i==7 || i==9){
      b[i][3]=c;
      c++;
    }
  }
  cin >> n;
  for(i=0;i<n;i++){
    cin >> s;
    j=0;
    while(j<s.size()){
      c = s[j];
      if(c=='0'){
        j++;
        continue;
      }
      int num=0;
      j++;
      while(s[j]==c){
        num++;
        j++;
      }
      num = check(num,c);
      cout << b[c-'0'][num];
    }
    cout << endl;
  }
  return 0;
}

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 = '\0';
    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 != '\0')
          cout << p;
        p = '\0';
      }
      x = j;
    }
    cout << endl;
  }
}

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

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

int main() {
    string code[9];
    code[0] = ".,!? ";
    code[1] = "abc";
    code[2] = "def";
    code[3] = "ghi";
    code[4] = "jkl";
    code[5] = "mno";
    code[6] = "pqrs";
    code[7] = "tuv";
    code[8] = "wxyz";
    int n;
    cin >> n;
    rep(i, n) {
        string c;
        cin >> c;
        int idx = -1, cnt = -1;
        rep(j, c.length()) {
            string t = "";
            t += c[j];
            int num = atoi(t.c_str());
            if (num == 0) {
                if (idx != -1 && cnt != -1) cout << code[idx][cnt];
                idx = -1;
                cnt = -1;
            }
            else {
                if (idx == -1 && cnt == -1) {
                    idx = num-1;
                    cnt = 0;
                }
                else {
                    cnt = (cnt+1)%code[idx].length();
                }
            }
        }
        cout << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string table[]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  char str[1280];
  int a;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>str;
    int r=0;
    char now='0';
    for(int i=0;str[i];i++){
            if(now!=str[i]){
                if(now!='0'){
		  cout<<table[now-'0'][(r-1)%table[now-'0'].size()];
                }
                r=1;
                now=str[i];
            }else r++;
    }
	    cout<<endl;
  }
  return 0;
}