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>
#include <cstdio>
using namespace std;

#define MAXLEN 1024

char *renovate(char *s);
char judge(char string, int c){

  if(string == '1'){
    if(c % 5 == 1){
      return '.';
    } else if(c % 5 == 2){
      return ',';
    } else if(c % 5 == 3){
      return '!';
    } else if(c % 5 == 4){
      return '?';
    } else if(c % 5 == 0){
      return ' ';
    }

  } else if(string == '2'){
    if(c % 3 == 1){
      return 'a';
    } else if(c % 3 == 2){
      return 'b';
    } else if(c % 3 == 0){
      return 'c';
    }
  } else if(string == '3'){
    if(c % 3 == 1){
      return 'd';
    } else if(c % 3 == 2){
      return 'e';
    } else if(c % 3 == 0){
      return 'f';
    }
  } else if(string == '4'){
    if(c % 3 == 1){
      return 'g';
    } else if(c % 3 == 2){
      return 'h';
    } else if(c % 3 == 0){
      return 'i';
    }
  } else if(string == '5'){
    if(c % 3 == 1){
      return 'j';
    } else if(c % 3 == 2){
      return 'k';
    } else if(c % 3 == 0){
      return 'l';
    }
  } else if(string == '6'){
    if(c % 3 == 1){
      return 'm';
    } else if(c % 3 == 2){
      return 'n';
    } else if(c % 3 == 0){
      return 'o';
    }
  } else if(string == '7'){
    if(c % 4 == 1){
      return 'p';
    } else if(c % 4 == 2){
      return 'q';
    } else if(c % 4 == 3){
      return 'r';
    } else if(c % 4 == 0){
      return 's';
    }
  } else if(string == '8'){
    if(c % 3 == 1){
      return 't';
    } else if(c % 3 == 2){
      return 'u';
    } else if(c % 3 == 0){
      return 'v';
    }
  } else if(string == '9'){
    if(c % 4 == 1){
      return 'w';
    } else if(c % 4 == 2){
      return 'x';
    } else if(c % 4 == 3){
      return 'y';
    } else if(c % 4 == 0){
      return 'z';
    }
  }

}
  
int main(void){
  char str[MAXLEN + 1];

  fgets(str, MAXLEN, stdin);

  if(str[strlen(str) - 1] == '\n'){
    str[strlen(str) - 1] = '\0';
  }

  cout << renovate(str) << endl;

  return 0;
}

char *renovate(char *s){
  char *answer = (char *)malloc(sizeof(s)), number = ' ';
  int i, j = 0, count = 0;

  if(s[strlen(s) - 1] != '0'){
    answer[0] = 'a';
    return answer;
  }

  for(i = 0; *(s + i) != '\0'; i++){
    if(*(s + i) != '0'){
      if(count == 0){
	number = *(s + i);
	count++;
      } else if(count != 0){
	count++;
      } 
    } else if(*(s + i) == '0'){
      if(number != ' '){
	answer[j++] = judge(number, count);
	count = 0;
	number = ' ';
      }
    }
  }

  answer[j] = '\0';

  return answer;
}

C++: // 2006_KeitaiMessage.cpp
//
#include <bits/stdc++.h>
using namespace std;
int n;
string m;
char d[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 len[10] = {-1, 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() <= len[a] ? x.length() - 1 : x.length()%len[a] - 1);
      cout << d[a][b];
    });
  cout << endl;
}

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

C++: ///
// File:  2006.cpp
// Author: ymiyamoto
//
// Created on Fri Nov 10 06:23:37 2017
//

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

static vector<string> arr({"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"});

int32_t main()
{
  uint32_t N;
  cin >> N;

  for (uint32_t i = 0; i < N; i++) {
    string str;
    cin >> str;
    uint32_t pre = 0;
    int32_t num = -1;
    for (uint32_t j = 0; j < str.size(); j++) {
      int32_t but = str[j] - '0';
      if (but == 0) {
        if (pre != 0) {
          cout << arr[pre][num];
        }
        pre = 0;
        num = -1;
      } else {
        pre = but;
        num++;
        num = num % arr[but].size();
      }
    }
    cout << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define NIL -1

int N;

int main()
{
    char com[][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 lens[] = {0, 5, 3, 3, 3, 3, 3, 4, 3, 4};
    std::cin >> N;
    std::string msg;


    for (int t = 0; t < N; t++) {
        std::cin >> msg;
        std::string res;
        int cnt = NIL;
        char btn = '#';

        bool isPressed0 = false;

        //find first index where character is not 0
        unsigned long start = 0;
        for (unsigned long i = 0; i < msg.size(); i++) {
            if (msg[i] != '0') {
                start = i + 1;
                btn = msg[i];
                cnt = 0;
                break;
            }
        }

        for (unsigned long i = start; i < msg.size(); i++) {
            //if 0 is already pushed
            if (msg[i] == '0' && isPressed0) { continue; }

            else if (msg[i] == '0' && !isPressed0) {
                int idx = (int) btn - '0';
                res += com[idx][cnt % lens[idx]];
                isPressed0 = true;
            }

            else if (msg[i] != '0' && isPressed0) {
                cnt = 0;
                btn = msg[i];
                isPressed0 = false;
            }

            else {
                cnt++;
            }
        }

        std::cout << res << std::endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
#define rep(i,j) for(int i = 0; i < (j); i++)
int main(){
	int n;
	cin >> n;
	string c[] = {"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};	
	while(n--){
		string str;
		cin >> str;
		string ans = "";
		rep(i,str.size()){
			if(str[i] == '0')continue;
			int sub = i;
			while(str[i] == str[++sub]);
			ans += c[str[sub-1]-48][(sub-i-1)%c[str[sub-1]-48].size()];
			i = sub;
		}
		cout << ans << endl;
	}	
	return 0;
}