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>

using namespace std;

string outputWord(string str);

int main() {
  int n;
  string tmp;
  cin>>n;
  getline(cin, tmp);
  while(n--) {
    string inputStr;
    getline(cin, inputStr);    
    cout<<outputWord(inputStr)<<endl;
  }
}

string outputWord(string str) {
  string ans, tmp;

  for(int i=0; i<str.length(); i++) {
    switch(str[i]) {
    case '0':
      ans += tmp;
      tmp.clear();
      break;
    case '1':
      if(tmp.length()==0 || tmp==" ") {
	tmp = ".";
      }
      else if(tmp == ".") {
	tmp = ",";
      }
      else if(tmp == ",") {
	tmp = "!";
      }
      else if(tmp == "!") {
	tmp = "?";
      }
      else if(tmp == "?") {
	tmp = " ";
      }
      break;
    case '2':
      if(tmp.length()==0 || tmp=="c") {
	tmp = "a";
      }
      else if(tmp == "a") {
	tmp = "b";
      }
      else if(tmp == "b") {
	tmp = "c";
      }
      break;
    case '3':
      if(tmp.length()==0 || tmp=="f") {
	tmp = "d";
      }
      else if(tmp == "d") {
	tmp = "e";
      }
      else if(tmp == "e") {
	tmp = "f";
      }
      break;
    case '4':
      if(tmp.length()==0 || tmp=="i") {
	tmp = "g";
      }
      else if(tmp == "g") {
	tmp = "h";
      }
      else if(tmp == "h") {
	tmp = "i";
      }
      break;
    case '5':
      if(tmp.length()==0 || tmp=="l") {
	tmp = "j";
      }
      else if(tmp == "j") {
	tmp = "k";
      }
      else if(tmp == "k") {
	tmp = "l";
      }
      break;
    case '6':
      if(tmp.length()==0 || tmp=="o") {
	tmp = "m";
      }
      else if(tmp == "m") {
	tmp = "n";
      }
      else if(tmp == "n") {
	tmp = "o";
      }
      break;
    case '7':
      if(tmp.length()==0 || tmp=="s") {
	tmp = "p";
      }
      else if(tmp == "p") {
	tmp = "q";
      }
      else if(tmp == "q") {
	tmp = "r";
      }
      else if(tmp == "r") {
	tmp = "s";
      }
      break;
    case '8':
      if(tmp.length()==0 || tmp=="v") {
	tmp = "t";
      }
      else if(tmp == "t") {
	tmp = "u";
      }
      else if(tmp == "u") {
	tmp = "v";
      }
      break;
    case '9':
      if(tmp.length()==0 || tmp=="z") {
	tmp = "w";
      }
      else if(tmp == "w") {
	tmp = "x";
      }
      else if(tmp == "x") {
	tmp = "y";
      }
      else if(tmp == "y") {
	tmp = "z";
      }
      break;
    }
  }

  return ans;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	string a;
	string d[10] = { "",".,!?","abc","def","ghi","jkl","mno",
		"pqrs","tuv","wxyz" };
	while (cin >> a) {
		char b;
		string c = "";
		for (int i = 0; i < a.length(); i++) {
			b = a[i];
			int i2 = i;
			while (a[i] == b) i++;
			int sum = i - i2;
			sum %= d[(int)b - '0'].length();
			sum--;
			c += d[(int)b-'0'][sum];
		}
		cout << c << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main(){

	string data[] = { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	char inp;
	int n, cnt, num;
	string ans;

	cin >> n;

	getchar();

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

		cnt = 0;
		ans = ("");

		while (1){

			inp = getchar();

			if (inp == '\n') break;
			if (inp != '0'){
				num = inp - '0';
				cnt++;
			}
			else{
				if (cnt > 0){
					ans += data[num-1][(cnt-1)%data[num-1].size()];
					cnt = 0;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

char data[10][5] = {'E','E','E','E','E',
		    '.', ',', '!' ,'?' ,' ',
		    'a', 'b', 'c', 'E', 'E',
		    'd','e','f','E','E',
		    'g','h','i','E','E',
		    'j','k','l','E','E',
		    'm','n','o','E','E',
		    'p','q','r','s','E',
		    't','u','v','E','E',
		    'w','x','y','z','E'};

string in;
int col=-1, row=0;
int num;
int state = 0;

int main(){
  int N;
  cin >> N;
  while(N--){
    cin.ignore();
    while(getline(cin,in)){
      bool onlyzero = true;
      for(int i = 0; i < in.length(); i++)
	if(in[i] != '0') onlyzero = false;

      if(onlyzero){
	cout << endl;
	continue;
      }

      for(int i = 0; i < in.length(); i++){
	if(in[i] == '0'){
	  if(col == -1) col++;
	  if(row >= 2 && row <= 6 || row == 8) num = 3;
	  else if(row == 1) num = 5;
	  else num = 4;
	
	  if(data[row][col%num] != 'E'){
	    cout << data[row][col%num];
	    state = 1;
	  }
	  col = -1;
	  row = 0;
	}else{
	  col++;
	  row=in[i]-'0';
	}
	if(i == in.length()-1){
	  if(state == 1) cout << endl;
	  state = 0;
	  col = -1;
	  row = 0;
	}
	
      }
      if(data[row][col%num] != 'E'){
	cout << data[row][col%num];
	//state = 1;
      }
      if(state == 1) cout << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main()
{
  string code[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  int len[] = {5, 3, 3, 3, 3, 3, 4, 3, 4};
  
  int N;
  cin >> N;
  while(N--){
    string s;
    cin >> s;
    char c = '#';
    int idx = 0;
    for(int i = 0; i < s.size(); i++){
      if(s[i] == '0'){
	if(c != '#') cout << c;
	c = '#';
	idx = 0;
      } else {
	c = code[s[i]-'0'-1][idx];
	idx = (idx + 1) % len[s[i]-'0'-1];
      }
    }
    cout << endl;
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    char code[][5] = {
        {0,0,0,0,0},
        {'.',',','!','?',' '},
        {97,98,99,0,0},
        {100,101,102,0,0},
        {103,104,105,0,0},
        {106,107,108,0,0},
        {109,110,111,0,0},
        {112,113,114,115,0},
        {116,117,118,0,0},
        {119,120,121,122,0}
    };
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string input;
        cin >> input;
        int num = 0;
        int index = 0;
        for (int j = 0; j < input.length(); ++j) {
            if (input[j] == '0') {
                cout << code[num][index];
                num = 0;
                index = 0;
            } else if (!index && !num) {
                num = input[j] - '0';
            } else {
                while(num) {
                    if (++index == 5) index = 0;
                    if (code[num][index]) break;
                }
            }
        }
        cout << endl;
    }
    return 0;
}