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<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<climits>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;

char moji(char x,int n){
  //x を nかい押したときに入力された時の文字
  if(x == '1'){
    switch ((n-1)%5){
    case 0:return '.';
    case 1:return ',';
    case 2:return '!';
    case 3:return '?';
    case 4:return ' ';
    }
  }
  if(x == '2')return 'a' + (n-1)%3;
  if(x == '3')return 'd' + (n-1)%3;
  if(x == '4')return 'g' + (n-1)%3;
  if(x == '5')return 'j' + (n-1)%3;
  if(x == '6')return 'm' + (n-1)%3;
  if(x == '7')return 'p' + (n-1)%4;
  if(x == '8')return 't' + (n-1)%3;
  if(x == '9')return 'w' + (n-1)%4;
  cout<< "error:" << x << ','<< n << endl;
  return -1;
}

string solve(const string &input){
  string output = "";
  int prev = input[0];//直前の入力
  int count = 0;//連続して入力された回数

  for(size_t i = 0;i < input.size();i++){
    const char &cur = input[i];

    if(cur == '0'){
      if(prev != '0')
	output.append(1, moji(prev,count));
      if(i < input.size()-1)prev = input[i+1];
      count = 0;
    }else if(cur == prev){
      //
      count++;
    }else{
      //入力が直前と異なる
      prev = cur;
      output.append(1, moji(cur,count));
      count = 0;
    }
  }
  return output;
}


int main(){
  ios::sync_with_stdio(false);
  int x;
  cin >> x; 
  for(int i = 0;i < x; ++i){
    string input;
    cin.ignore();
    cin >> input;
    //cin.ignore();
    cout << solve(input) << 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;
			}
			if(i&&s[i-1]!=s[i])cnt=0;
			else cnt++;
		}
		cout<<ans<<endl;
	}
}

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

int main() {

  char d[5] = { '.', ',', '!', '?', ' ' };

  int m[10] = { 5, 3, 3, 3, 3,  3,  4,  3,  4 };
  int h[10] = { 0, 0, 3, 6, 9, 12, 15, 19, 22 };

  long long int n;
  cin >> n;

  for ( long long int i = 0; i < n; i++ ) {

    string in;
    cin >> in;

    long long int a = -1;
    long long int b = -1;
    char c;

    for ( long long int j = 0; j < in.size(); j++ ) {

      if ( in[j] == '0' ) {
	if ( a == -1 ) continue;
	b %= m[a-1];
	if ( a == 1 ) {
	  c = d[b];
	}else {
	  c = 'a' + h[a-1] + b;
	}
	cout << c;
	a = -1;
	b = -1;
      }else {
	a = in[j] - '0';
	b++;
      }

    }

    cout << endl;

  }

  return 0;

}

C++: #include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
string keys[10] = {
  "",
  ".,!? ",
  "abc",
  "def",
  "ghi",
  "jkl",
  "mno",
  "pqrs",
  "tuv",
  "wxyz"
};
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    string key_string;
    cin >> key_string;
    string ans;
    bool in_loop = false;
    int loop_ind = 0;
    int cur_key;
    for(int j = 0; j < key_string.size(); j++){
      if(key_string[j] == '0'){
        if(in_loop){
          ans += keys[cur_key][loop_ind];
          in_loop = false;
        }
      } else {
        if(in_loop){
          loop_ind = (loop_ind + 1) % keys[cur_key].size();
        } else {
          in_loop = true;
          loop_ind = 0;
          cur_key = key_string[j] - '0';
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int lli;

string charset[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"}
};
int loop[10] = {0, 5, 3, 3, 3, 3, 3, 4, 3, 4};

int main(){
	int N;
	cin >> N;
	vector<string> ansvec;
	for (int n = 0; n < N; n++){
		string s;
		cin >> s;

		int i = 0;
		int push = -1;
		string ans = "";
		while (i < s.length()){
			int num = stoi(s.substr(i, 1));
			if (num != 0){
				int thisnum = num;
				while (num != 0){
					push++;
					i++;
					num = stoi(s.substr(i, 1));
				}
				ans += charset[thisnum][push % loop[thisnum]];
				push = -1;
			}
			i++;
		}
		ansvec.push_back(ans);
	}

	for (auto it = ansvec.begin(); it != ansvec.end(); it++){
		cout << *it << endl;
	}
	return 0;
}

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

void strplus(string& s, int nn, int c)
{
	switch (nn) {
	case 0:
		break;
	case 1:
		switch (c % 5) {
		case 0:
			s += ".";
			break;
		case 1:
			s += ",";
			break;
		case 2:
			s += "!";
			break;
		case 3:
			s += "?";
			break;
		case 4:
			s += " ";
			break;
		}
		break;
	case 2:
		switch (c % 3) {
		case 0:
			s += "a";
			break;
		case 1:
			s += "b";
			break;
		case 2:
			s += "c";
			break;
		}
		break;
	case 3:
		switch (c % 3) {
		case 0:
			s += "d";
			break;
		case 1:
			s += "e";
			break;
		case 2:
			s += "f";
			break;
		}
		break;
	case 4:
		switch (c % 3) {
		case 0:
			s += "g";
			break;
		case 1:
			s += "h";
			break;
		case 2:
			s += "i";
			break;
		}
		break;
	case 5:
		switch (c % 3) {
		case 0:
			s += "j";
			break;
		case 1:
			s += "k";
			break;
		case 2:
			s += "l";
			break;
		}
		break;
	case 6:
		switch (c % 3) {
		case 0:
			s += "m";
			break;
		case 1:
			s += "n";
			break;
		case 2:
			s += "o";
			break;
		}
		break;
	case 7:
		switch (c % 4) {
		case 0:
			s += "p";
			break;
		case 1:
			s += "q";
			break;
		case 2:
			s += "r";
			break;
		case 3:
			s += "s";
			break;
		}
		break;
	case 8:
		switch (c % 3) {
		case 0:
			s += "t";
			break;
		case 1:
			s += "u";
			break;
		case 2:
			s += "v";
			break;
		}
		break;
	case 9:
		switch (c % 4) {
		case 0:
			s += "w";
			break;
		case 1:
			s += "x";
			break;
		case 2:
			s += "y";
			break;
		case 3:
			s += "z";
			break;
		}
		break;
	}
}

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

	for (int i = 0; i < n; i++) {
		string str;
		string temp;

		cin >> temp;

		int nownum = 0;
		int count = 0;

		for (unsigned int j = 0; j < temp.size(); j++) {
			if (stoi(temp.substr(j, 1)) == 0) {
				strplus(str, nownum, count);
				nownum = 0;
			}
			else {
				if (nownum == stoi(temp.substr(j, 1))) {
					count++;
				}
				else {
					nownum = stoi(temp.substr(j, 1));
					count = 0;
				}
			}
		}

		cout << str << endl;
	}

	return 0;
}