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 <bits/stdc++.h>
using namespace std;

vector<vector<char> > buttons { {'.',',','!','?',' '}, {'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'}};

char push(int button, int times) {
  return buttons[button - 1][(times - 1) % buttons[button - 1].size()];
}

void solve(string s) {
  int t = 0;
  int before = 0;
  for (auto c : s) {
    if (c == '0') {if (t != 0) cout << push(before, t); t = 0;}
    else {
      t++;
      before = atoi(&c);
    }
  }
  if (t!= 0) cout << push(before, t);
  cout << endl;
};

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

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

int main()
{
    string phone[10] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    int n;
    string input;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> input;
        int l = input.length();
        int j = 0;
        while(1){
            int c1 = 0;
            while(c1 == 0 && j < l){
                c1 = input[j] - '0';
                j++;
            }
            if(j == l) break;
            int l2 = phone[c1 - 1].length();
            int k = 0;
            while(c1 == input[j] - '0'){
                j++;
                k++;
            }
            cout << phone[c1 - 1][k % l2];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;

char letter[] = {'.', ',', '!', '?', ' ', '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'};

char output(int b, int c)
{
    switch (b) {
    case 1:
        return letter[0 + (c % 5)];
        break;
    case 2:
        return letter[5 + (c % 3)];
        break;
    case 3:
        return letter[8 + (c % 3)];
        break;
    case 4:
        return letter[11 + (c % 3)];
        break;
    case 5:
        return letter[14 + (c % 3)];
        break;
    case 6:
        return letter[17 + (c % 3)];
        break;
    case 7:
        return letter[20 + (c % 4)];
        break;
    case 8:
        return letter[24 + (c % 3)];
        break;
    case 9:
        return letter[27 + (c % 4)];
        break;
    }
}

int main()
{
    int n;
    cin >> n;
    for (int cnt = 0; cnt < n; cnt++) {
        string str;
        cin >> str;
        int button = -1;
        int count = -1;
        for (char c : str) {
            if (c == '0') {
                if (button != -1) {
                    cout << output(button, count);
                }
                count = -1;
                button = -1;
            } else {
                button = c - '0';
                count++;
            }
        }
        cout << endl;
    }
    return 0;
}

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

int main(void)
{
  int n;
  char buf[1026];
  int count=0;
  int tmp;

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

C++: #include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int main() {
	char m[10][10] = {
		"",
		".,!? ",
		"abc",
		"def",
		"ghi",
		"jkl",
		"mno",
		"pqrs",
		"tuv",
		"wxyz",
	};

	int n; cin >> n;
	for (int t = 0; t < n; ++t) {
		string ans = "";
		string str; cin >> str;
		int Key = -1, cnt = 0;
		for (int i = 0; i < str.size(); ++i) {
			int key = str[i]-'0';
			if (key == 0) {
				if (cnt > 0) {
					ans += m[Key][(cnt-1)%strlen(m[Key])];
				}
				cnt = 0;
			}
			else {
				Key = key;
				++cnt;
			}
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#define REP(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main()
{
  char keitai[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', '*'},
  };
  string s;
  int x , c;
  char p;
  while(getline(cin, s)){
    x = c = 0;
    p = '\0';
    REP(i, s.size()){
      int j;
      j = s[i] - '0';
      if(j){
        if(x == j){
          if(keitai[j][c + 1] == '*'){
            c = 0;
            p = keitai[j][c];
          }else{
            c++;
            p = keitai[j][c];
            //cout << "i = " << i << ", p = " << p << endl;
          }
        }else{
          c = 0;
          p = keitai[j][c];
        }
      }else{
        if(p != '\0')
          cout << p;
        p = '\0';
      }
      x = j;
    }
    cout << endl;
  }
}