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

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

string solve(string in){
  string res="";
  int c=0;
  int n_in=0;
  for(int i=0;i<in.size();i++){
    int t_in=in[i]-'0';
    if(t_in==0){
      if(n_in!=0){
        res+=push[n_in][(c%push[n_in].size())];
      }
      n_in=0;
      c=0;
    }else{
      if(t_in==n_in){
        c++;
      }else{
        c=0;
	n_in=t_in;
      }
    }
  }
  return res;
}



int main(){
  string in;
  while(cin>>in){
    string ans=solve(in);
    if(ans.size()!=0){
      cout<<ans<<endl;
    }
  }
}

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

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

int main(){
	int n;
	std::cin >> n;
	for(int i = 0; i < n; ++i){
		std::string s;
		std::cin>>s;
		int key[10];
		for(int i=0;i<10;++i)key[i]=0;
		int on=0;
		for(int i = 0; i < s.size();++i){
			if(s[i]!='0'){
				key[s[i]-'0']++;
				on=s[i]-'0';
				
			}else{
				if(on){
					int cnt=key[on];
					if(on==7 || on==9 && key[on]>=4)cnt%=4;
					else if(on==1 && key[on]>=5)cnt%=5;
					else if(on>=1 && on<=9 && on!=9 && on!=7 && on!=1 && key[on]>=3)cnt%=3;
					std::cout<<f(on,cnt);
					//std::cout<<key[on]<<std::endl;
					for(int i=0;i<10;++i)key[i]=0;
				}
				on=0;
			}//44033055505550666011011111090666077705550301110
		}
		std::cout<<std::endl;
	}
	return 0;
}

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', '*'},
  };
  int n;
  cin >> n;
  cin.ignore();
  string s;
  int x , c;
  char p;
  REP(k, n){
    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];
          }
        }else{
          c = 0;
          p = keitai[j][c];
        }
      }else{
        if(p != '\0')
          cout << p;
        p = '\0';
      }
      x = j;
    }
    cout << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}


int main(){
	vector<string>keistr(10);
	keistr[1] = ".,!? ";
	keistr[2] = "abc";
	keistr[3] = "def";
	keistr[4] = "ghi";
	keistr[5] = "jkl";
	keistr[6] = "mno";
	keistr[7] = "pqrs";
	keistr[8] = "tuv";
	keistr[9] = "wxyz";
	int n;
	cin >> n;
	REP(i,n){
		string in_str;
		cin >> in_str;
		int cnt = -1;
		REP(j,in_str.size()){
			if(in_str[j]=='0'){
				if(cnt>=0){
					int pos = in_str[j-1] - '0';
					cout << keistr[pos][cnt%keistr[pos].size()];
					cnt = -1;
				}
			}else{
				cnt++;
			}
		}
		cout  << endl;
	}
}

C++: #include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(){
  string kigo = ".,!? ";
  string a = "abc";
  string d = "def";
  string g = "ghi";
  string j = "jkl";
  string m = "mno";
  string p = "pqrs";
  string t = "tuv";
  string w = "wxyz";
  string syu;
  int keta,n,count;
  int flag1 = 0;
  int flag2 = 0;
  cin >> n;
  string nn;
  for(int i = 0; i < n;i++){
    cin >> nn;
    syu = "";
    for(int i = 0; i < nn.length();i++){
      if(nn[i] == '1'){
        flag1 = 1;
        flag2 += 1;
      }else if(nn[i] == '2'){
        flag1 = 2;
        flag2 += 1;
      }else if(nn[i] == '3'){
        flag1 = 3;
        flag2 += 1;
      }else if(nn[i] == '4' ){
        flag1 = 4;
        flag2 += 1;
      }else if(nn[i] == '5'){
        flag1 = 5;
        flag2 += 1;
      }else if(nn[i]== '6'){
        flag1 = 6;
        flag2 += 1;
      }else if(nn[i] == '7'){
        flag1 = 7;
        flag2 += 1;
      }else if(nn[i] == '8'){
        flag1 = 8;
        flag2 += 1;
      }else if(nn[i] == '9'){
        flag1 = 9;
        flag2 += 1;
      }else if(nn[i] == '0'){
        if(flag1 == 0){
        }else{
          flag2 -= 1;
          if(flag1 == 1){
            syu += kigo[(flag2)%5];
            flag1 = 0;
          }else if(flag1 == 2){
            syu += a[flag2%3];
            flag1 = 0;
          }else if(flag1 == 3){
            syu += d[flag2%3];
            flag1 = 0;
          }else if(flag1 == 4){
            syu += g[flag2%3];
            flag1 = 0;
          }else if(flag1 == 5){
            syu += j[flag2%3];
            flag1 = 0;
          }else if(flag1 == 6){
            syu += m[flag2%3];
            flag1 = 0;
          }else if(flag1 == 7){
            syu += p[flag2%4];
            flag1 = 0;
          }else if(flag1 == 8){
            syu += t[flag2%3];
            flag1 = 0;
          }else if(flag1 == 9){
            syu += w[flag2%4];
            flag1 = 0;
          }
          flag2 = 0;
        }
      }
    }
      cout << syu << endl;
  }
}