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<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

string button[10] = {"12345678", ".,!? ", "abc", "def", "ghi", "jkl" , "mno", "pqrs", "tuv", "wxyz" };


int main()
{

    int n;
    cin >> n;
    string s;
    getline(cin, s);
    while(n--)
    {
        getline(cin, s);
        int bnum = 0;
        int pushnum = 0;

        REP(s.size() - 1)
        {
            if(s[i] == '0' && pushnum > 0)
            {
                cout << button[bnum][(pushnum + button[bnum].size() - 1) % button[bnum].size()];
                pushnum = 0;
                bnum = 0;
            }
            if(s[i] != '0'){ pushnum = (pushnum+1) ; bnum = s[i] - '0';}

        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

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

  char b[] = ".,!? ";
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    int cnt = 0, ssz = s.size();
    if (s[0] != '0') cnt++;

    for (int j = 1; j < ssz; j++) {
      if (s[j] != '0') cnt++;
      else if (s[j - 1] == '0') cnt = 0;
      else {
        if (s[j - 1] == '1') {
          printf("%c", b[(cnt - 1 + 5) % 5]);
        } else if (s[j - 1] == '7') {
          printf("%c", 'p' + (cnt - 1 + 4) % 4);
        } else if (s[j - 1] == '9') {
          printf("%c", 'w' + (cnt - 1 + 4) % 4);
        } else {
          if (s[j - 1] < '7') {
            printf("%c", 'a' + 3 * (s[j - 1] - '2') + (cnt - 1 + 3) % 3);
          } else {
            printf("%c", 't' + 3 * (s[j - 1] - '8') + (cnt - 1 + 3) % 3);
          }
        }
        cnt = 0;
      }
    }
    cout << endl;
  }

  return 0;
}

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

using namespace std;

string data[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

main(){
  int n;
  cin >> n;
  getchar();
  while(n--){
    char in;
    string out;
    char pre = '0';
    char c = 0;
    int p = 0;
    while(1){
      scanf("%c", &in);
      if(in == '\n') break;
      if(in == '0'){
        if(c != 0) out += c;
        c = 0;
      }else{
        if(pre != in) p = 0;
        else p = (p+1)%((int)data[in-'0'].size());
        c = data[in-'0'][p];
      }
      pre = in;
    }
    cout << out << endl;
  }
  return 0;
}

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

int main(){
  int n;
  string bottan[]={
    ".,!? ", // 1
    "abc", // 2
    "def", // 3
    "ghi", // 4
    "jkl", // 5
    "mno", // 6
    "pqrs", // 7
    "tuv", // 8
    "wxyz", // 9
  };
  int cnt[] = {5,3,3,3,3,3,4,3,4};
  
  cin >> n;
  while(n--){
    string str; cin >> str;
    int len = str.size();
    int cnt1=0,cnt2=0;
    for(int i=0;i<len;i++){
      if(str[i] == '0' && cnt1 != 0){
	cout << bottan[cnt1-1][cnt2-1];
	cnt1 = 0; cnt2 = 0;
      }
      else {
	if(cnt1 == 0){
	  cnt1 = str[i] - '0';
	}
	cnt2 = cnt2%cnt[cnt1-1] + 1;
      }
    }
    cout << endl;
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int i;
	cin >> i;
	char n;
	string s;
	int n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0, n8 = 0, n9 = 0;
	for (int j = 0; j<i; j++) {
		cin >> n;
		do {
			if (n == ' ' || n == '\n' || n == '	')break;
			switch (n) {
			case '1':
				n1++;
				break;
			case '2':
				n2++;
				break;
			case '3':
				n3++;
				break;
			case '4':
				n4++;
				break;
			case '5':
				n5++;
				break;
			case '6':
				n6++;
				break;
			case '7':
				n7++;
				break;
			case '8':
				n8++;
				break;
			case '9':
				n9++;
				break;
			default:
				if (n1) {
					if (n1 == 1) {
						s += '.';
					}
					else if (n1 == 2) {
						s += ',';
					}
					else if (n1 == 3) {
						s += '!';
					}
					else {
						s += '?';
					}
					n1 = 0;
				}
				else if (n2) {
					if (n2 % 3 == 1) {
						s += 'a';
					}
					else if (n2 % 3 == 2) {
						s += 'b';
					}
					else {
						s += 'c';
					}
					n2 = 0;
				}
				else if (n3) {
					if (n3 % 3 == 1) {
						s += 'd';
					}
					else if (n3 % 3 == 2) {
						s += 'e';
					}
					else {
						s += 'f';
					}
					n3 = 0;
				}
				else if (n4) {
					if (n4 % 3 == 1) {
						s += 'g';
					}
					else if (n4 % 3 == 2) {
						s += 'h';
					}
					else {
						s += 'i';
					}
					n4 = 0;
				}
				else if (n5) {
					if (n5 % 3 == 1) {
						s += 'j';
					}
					else if (n5 % 3 == 2) {
						s += 'k';
					}
					else {
						s += 'l';
					}
					n5 = 0;
				}
				else if (n6) {
					if (n6 % 3 == 1) {
						s += 'm';
					}
					else if (n6 % 3 == 2) {
						s += 'n';
					}
					else {
						s += 'o';
					}
					n6 = 0;
				}
				else if (n7) {
					if (n7 % 4 == 1) {
						s += 'p';
					}
					else if (n7 % 4 == 2) {
						s += 'q';
					}
					else if (n7 % 4 == 3) {
						s += 'r';
					}
					else {
						s += 's';
					}
					n7 = 0;
				}
				else if (n8) {
					if (n8 % 3 == 1) {
						s += 't';
					}
					else if (n8 % 3 == 2) {
						s += 'u';
					}
					else {
						s += 'v';
					}
					n8 = 0;
				}
				else if (n9) {
					if (n9 % 4 == 1) {
						s += 'w';
					}
					else if (n9 % 4 == 2) {
						s += 'x';
					}
					else if (n9 % 4 == 3) {
						s += 'y';
					}
					else {
						s += 'z';
					}
					n9 = 0;
				}
			}
		} while (cin >> n);
		cout << s << endl;
		s = "";
	}
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		string key[]={".,!?, ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
		string input;
		cin>>input;
		stringstream b(input);
		int num=0,count=0;
		while(1){
			char c;
			if(!b>>c)break;
			int input=c-'0';
			if(input!=0){
				count++;
				num=input;
			}
			else {
				if(count!=0)
					cout<<key[num-1][(count-1)%key[num-1].size()];
				num=0;count=0;
			}
		}
		cout<<endl;
	}
	return 0;
}