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 <stdio.h>
#include <string.h>

const char word[9][6] = {{".,!? "},{"abc"},{"def"},{"ghi"},{"jkl"},{"mno"},{"pqrs"},{"tuv"},{"wxyz"}};
const char len[9] = {5,3,3,3,3,3,4,3,4};
int main(void){
	char str[1025], tmp;
	int n, i, j, count;
	scanf("%d%*c",&n);
	for(i = 0;i < n;i++){
		gets(str);
		str[strlen(str)] = '\0';
		j = 0;
		while(str[j] != '\0'){
			tmp = str[j];
			if(tmp != '0'){
				count = 1;
				while(str[++j] == tmp)
					count++;
				putchar(word[tmp - '1'][(count - 1) % len[tmp - '1']]);
			}
			else
				j++;
		}
		printf("\n");
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  char str[100000]={};
  char moji[10][6]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  int i;
  int n;

  cin>>n;
  rep(i,n){
    cin>>str;
    int len=strlen(str);
    int j=0;
    while(j<len){
      int num=0;
      while(str[j]!='0'){
	j++;
	num++;
      }
      if(j==0){
	j++;
	continue;
      }
      int a=str[j-1]-'0';
      if(a==1)
	cout<<moji[a][(num-1)%5];
      else if((a>1 && a<7)|| a==8)
	cout<<moji[a][(num-1)%3];
      else
	cout<<moji[a][(num-1)%4];
      j++;
    }
    cout<<endl;
  }
}

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

int main(){
  int prev=10,n,c=0;
  string str;
  char s,buf='\0';
  char keymap[9][5]={ {'.',',','!','?',' '},
		      {'a','b','c','\0','\0'},
		      {'d','e','f','\0','\0'},
		      {'g','h','i','\0','\0'},
		      {'j','k','l','\0','\0'},
		      {'m','n','o','\0','\0'},
		      {'p','q','r','s','\0'},
		      {'t','u','v','\0','\0'},
		      {'w','x','y','z','\0'}};
  cin>>n;

  while(n--){
    cin>>str;
    for(int i=0;i<str.length();i++){
      s=str.at(i);
      if(c!=0&&s=='0')cout<<buf,c=0,buf=0;
      switch (s){
      case '1':
	buf=keymap[0][(c++)%5];
	break;
      case '2':
	buf=keymap[1][(c++)%3];
	break;
      case '3':
	buf=keymap[2][(c++)%3];
	break;
      case '4':
	buf=keymap[3][(c++)%3];
	break;
      case '5':
	buf=keymap[4][(c++)%3];
	break;
      case '6':
	buf=keymap[5][(c++)%3];
	break;
      case '7':
	buf=keymap[6][(c++)%3];
	break;
      case '8':
	buf=keymap[7][(c++)%4];
	break;
      case '9':
	buf=keymap[8][(c++)%3];
	break;
      }
    }
    buf=0;
    cout<<endl;
  }
}

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,b;
  cin >>b;
  for(int j=0;j<b;j++){ // 入力
    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++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

const char gKeys[10][6] 
= {"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};


int main(){
  char buf[1025];
  int N;
  while(~scanf("%d",&N)){
    for(int t=0;t<N;t++){
      scanf("%s",buf);
      queue<int> que;
      for(int i=0;i<strlen(buf);i++){
	if(buf[i] != '0') que.push(buf[i]-'0');
	else if(buf[i] == '0'){
	  if(que.empty()) continue;
	  int idx = que.size()-1;
	  int key = que.front();
	  int pos = idx%strlen(gKeys[key]);
	  printf("%c",gKeys[key][pos]);
	  que = queue<int>(); //clear que
	}
      }
      printf("\n");
    }
  }
}