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 argc, char *argv[])
{
    string map[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno",
        "pqrs", "tuv", "wxyz"};
    string line;
    int n, cnt, num;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> line;
        cnt = 0;
        for (int j = 0; j < line.length(); ++j) {
            if (line[j] == '0' && j != 0 && line[j - 1] != '0') {
                num = line[j - 1] - '0';
                cout << map[num][(cnt - 1) % map[num].length()];
                cnt = 0;
            } else if (line[j]) {
                cnt++;
            }
        }
        cout << endl;
    }
    return 0;
}

C++: // 2006_KeitaiMessage.cpp
//
#include <bits/stdc++.h>
using namespace std;
int n;
string m;
char d[9][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'},
};
int len[9] = {5, 3, 3, 3, 3, 3, 4, 3, 4};

vector<string> split(string &str, char sep) {
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while(getline(ss, buffer, sep)) {
    if(buffer != "") v.push_back(buffer);
  }
  return v;
}

void solve() {
  vector<string> v1 = split(m, '0');
  for_each(v1.begin(), v1.end(), [](string& x) {
      int a = x[0] - '0';
      int b = x.length();
      int c = (b <= len[a - 1] ? b - 1 : b % len[a - 1] - 1);
      cout << d[a - 1][c];
    });
  cout << endl;
}

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> m;
    solve();
  }
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  cin.ignore();

  string rule[10] = {"", ".,!? ", "abc", "def", "ghi",
                     "jkl","mno", "pqrs", "tuv", "wxyz"};
  
  for(int i=0; i<n; i++){
    string s;
    getline(cin, s);

    string ans = "", temp = "";
    int before = 0, index = 0;
    for(int j=0; j<s.size(); j++){
      if(s[j] - '0' == 0){
        ans += temp;
        temp = "";
        index = 0;
      }else if(before == s[j] - '0'){
        temp = rule[before][index];
        index = (index+1)%rule[before].size();
      }else{
        temp = rule[s[j] - '0'][0];
        index = 1;
      }
      before = s[j] - '0';
    }

    cout << ans << endl;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

int main() {
    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;

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

        int cnt = 0;
        int now = 0;
        rep(i, s.size()) {
            if (s[i] == '0') {
                if (cnt != 0) {
                    cout << t[now][(cnt - 1) % t[now].size()];
                    cnt = 0;
                }
            } else {
                cnt++;
                now = s[i] - '0';
            }
        }
        cout << "\n";
    }

    return 0;
}

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

int main(){
  vector<vector<char> > v;
  vector<char> mv;

  mv.push_back(' ');mv.push_back('.');mv.push_back(',');mv.push_back('!');mv.push_back('?');
  v.push_back(mv);
  mv.clear();

  mv.push_back('c');mv.push_back('a');mv.push_back('b');
  v.push_back(mv);
  mv.clear();

  mv.push_back('f');mv.push_back('d');mv.push_back('e');
  v.push_back(mv);
  mv.clear();

  mv.push_back('i');mv.push_back('g');mv.push_back('h');
  v.push_back(mv);
  mv.clear();

  mv.push_back('l');mv.push_back('j');mv.push_back('k');
  v.push_back(mv);
  mv.clear();

  mv.push_back('o');mv.push_back('m');mv.push_back('n');
  v.push_back(mv);
  mv.clear();

  mv.push_back('s');mv.push_back('p');mv.push_back('q');mv.push_back('r');
  v.push_back(mv);
  mv.clear();

  mv.push_back('v');mv.push_back('t');mv.push_back('u');
  v.push_back(mv);
  mv.clear();

  mv.push_back('z');mv.push_back('w');mv.push_back('x');mv.push_back('y');
  v.push_back(mv);
  mv.clear();

  string s;
  int a,i,cou,n,cou2;
  while(cin >> s){ // 入力
    a=s.size();
    //cout <<a<< ' ';//////////////////
    i=0;
    cou2=0;
    while(i<a){//改行まで
      cou=0;
      n=0;
      while(s[i]!='0'&&i<a){//０まで
	if(n!=s[i]-'0')cou=0;
	n=s[i]-'0';
	i++;
	cou++;
      }
      i++;
      //cout <<n<< cou<< ' ';/////////////////
      if(cou!=0&&i<=a){
	if(n==8||n==2||n==3||n==4||n==5||n==6)cou=cou%3;
	else if(n==7||n==9)cou=cou%4;
	else if(n==1)cou=cou%5;

	cout<<v[n-1][cou];
	cou2++;
      }
    }
    if(cou2!=0)cout<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<bitset>
#include<map>
using namespace std;

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


string s;
bool input(){
  s="";
  if(!(cin>>s)){
    return false;
  }

  return true;
}


string solve(){
  string res = "";
  int n=-1;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      if(n==-1)continue;
      int tmp = s[i-1]-'0';
      res += list[tmp-1][n%list[tmp].size()];
      n=-1;
    }else{
      n++;
    }
  }
  return res;
}

int main(){
  int c=0;
  cin>>c;
  for(int i=0;i<c;i++){
    input();
    string ans = solve();
    if(ans.size()!=0)cout<<ans<<endl;
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  char hyou[9][5]={
    {' ','.',',','!','?'},
    {'c','a','b','0','0'},
    {'f','d','e','0','0'},
    {'i','g','h','0','0'},
    {'l','j','k','0','0'},
    {'o','m','n','0','0'},
    {'s','p','q','r','0'},
    {'v','t','u','0','0'},
    {'z','w','x','y','0'}
  };
  string a;
  int n,b=1;
  cin>>n;
  for(int i=0;i<n;i++){
    b=1;
    cin>>a;
    if(a.size()==1)cout<<hyou[a[0]-'0'][1];
    int size=a.size();
    for(int j=0;j<size-1;j++){
      if(a[j]=='0'){
	b=1;
	continue;
      }
      if(a[j]==a[j+1])b++;
      else{
	if(a[j]=='7'||a[j]=='9')b%=4;
	else if(a[j]=='1')b%=5;
	else b%=3;
	cout<<hyou[a[j]-'0'-1][b];
      }
    }
    cout<<endl;
  }
  return 0;
}