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 <cstring>
#include <cstdlib>
using namespace std;
int main()
{
	int n, i, j, k, c, d, x;
	char s[1025], t[10][6] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> s;
		for (j = x = 0, d = 0; j < strlen(s); j++, d = c)
		{
			c = s[j] - '0';
			if (c == 0 && d != 0)
				cout << t[d-1][x%strlen(t[d-1])];
			else if (d == c)
				x++;
			else
				x = 0;
		}
		cout << endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep( i, begin, end) for( int i = begin; i < end; i++ )
using namespace std;
 
string button[10] = { "", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
 
int main() {
    int n;
    cin >> n;
    rep( i, 0, n ) {
        string input, message = "";
        cin >> input;
        int key = 0, position = 0;
        rep( i, 0, input.size() ) {
            if ( input[i] == '0' ) {
                if ( key == 0 )
                    continue;
                position %= button[key].size();
                message += button[key][position];
                key = 0;
                position = 0;
            }
            else if ( key == 0 ) {
                key = input[i] - '0';
                position = 0;
            }
            else if ( key == input[i] - '0') {
                position++;
            }
        }
        cout << message << endl;
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>

int main() {

  int left, right;
  char key[10][10] = {
    {},
    {'.', ',', '!', '?', ' '},
    {'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 size[10] = {0, 5, 3, 3, 3, 3, 3, 4, 3, 4};
  int N;
  char str[1024];
  
  std::cin >> N;
  
  for(int t = 0; t < N; ++t) {  
    scanf("%s", str);

    std::vector<char> buffer;
    int n = strlen(str);
  
    left = right = 0;
    for(int i = 0; right <= n; ++right) {
      if( str[left] != str[right] ) {
        if( str[left] != '0' ) {
          buffer.push_back(key[str[left] - '0'][(right-left-1)%size[str[left]-'0']]);
        }
        left = right;
      }
    }
    buffer.push_back('\0');

    std::cout << &buffer[0] << std::endl;
    buffer.clear();
  }
  
  return 0;
}

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

int boo(int x, int y){
	if(x%y) return x%y -1;
	else return y - 1;
}

char foo(string str,int mk, int i){
	char ch, mozi[16] = "00adgjmptw", mozi1[8] = " .,!?";
	if(str[mk] - '0' == 1) ch = mozi1[(i - mk)%5];
	else if(((str[mk] - '0') == 7) || ((str[mk] - '0') == 9)) ch = mozi[str[mk] - '0'] + boo(i - mk, 4);
	else ch = mozi[str[mk] - '0'] + boo(i - mk, 3);
	return ch;
}

int main(){
	int N, mk, count, temp;
	int i, j, k;
	string str;
	char ch[2000];
	
	cin>>N;
	
	for(i = 0; i < N; i++){
		mk=0; count=0;
		cin>>str;
		for(j = 0; j < (int)str.size(); j++){
			if(str[j] == '0'){
				if(mk != j)ch[count++] = foo(str, mk, j);
				mk =  j + 1;
			}
		}
		
		for(j = 0; j < count; j++) cout<<ch[j];
		if(count)cout<<endl;
	}
	
	return 0;
}

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

int main(){

  string s;
  int n;
  char in;
  int num=0 , count=0;

  cin >> n;
  getchar();

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

    s = "";
    
    while(scanf("%c",&in)){
      if(in == '\n' ){ break; }

      else if(in == '0'){
 
	  if(num==2)
	    s += 'a'+(count-1)%3;
	  else if(num==3)
	    s += 'd'+(count-1)%3;
	  else if(num==4)
	    s += 'g'+(count-1)%3;
	  else if(num==5)
	    s += 'j'+(count-1)%3;
	  else if(num==6)
	    s += 'm'+(count-1)%3;
	  else if(num==7)
	    s += 'p'+(count-1)%4;
	  else if(num==8)
	    s += 't'+(count-1)%3;
	  else if(num==9)
	    s += 'w'+(count-1)%4;
	  else if(num==1){
	    switch((count-1)%5){
	    case 0: s+='.'; break;
	    case 1: s+=','; break;
	    case 2: s+='!'; break;
	    case 3: s+='?'; break;
	    default: s+=' ';
	    }
	  }

	  num = 0;
	  count = 0;

      }
      //kakutei

      else{
	if(in-'0' == num)
	  count ++;
	else{
	  num = in-'0';
	  count = 1;
	}
      }
    }
    //while

    cout << s << endl;

  }
	    
  return 0;
}