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

string order;
vector<int> num;
vector<char> word;
int n;
char button[9][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 main()
{
        int but = 0,push = 0;
        cin >> n;
        for(int i=0;i<n;i++){
                cin >> order;
                for(int j=0;j<order.size();j++){
                        num.push_back((int)(order[j]-'0'));
                }
                for(int j=0;j<num.size();j++){
                        if(1<=num[j] && num[j]<=9 && but==0){
                                but = num[j];
                        }else if(1<=num[j] && num[j]<=9 && but!=0){
                                push++; //cout << "pushed" << endl;
                        }else if(num[j]==0 && but && but!=1 && but!=7 && but!=9){
                                word.push_back(button[but-1][push%3]); //cout << button[but-1][push%3] << endl;
                                push = 0;
                                but = 0;
                        }else if(num[j]==0 && but && (but==7 || but==9)){
                                word.push_back(button[but-1][push%4]); //cout << button[but-1][push%4] << endl;
                                push = 0;
                                but = 0;
                        }else if(num[j]==0 && but && but==1){
                                word.push_back(button[but-1][push%5]);
                                push = 0;
                                but = 0;
                        }else if(num[j]==0 && !but){
                                continue;
                        }
                }
                for(int k=0;k<word.size();k++){
                        cout << word[k];
                }
                cout << endl;
                word.clear();
                num.clear();
        }

        return 0;

}

C++: #include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

int main() {
	vector< string > keitai;

	keitai.push_back(".,!? "); keitai.push_back("abc"); keitai.push_back("def"); keitai.push_back("ghi"); keitai.push_back("jkl");
	keitai.push_back("mno"); keitai.push_back("pqrs"); keitai.push_back("tuv"); keitai.push_back("wxyz");

	vector< int > count(keitai.size(), 0);

	int n;
	cin >> n;

	vector< string > s;
	for(int i = 0; i < n; i++) {
		string tmp;
		cin >> tmp;
		s.push_back(tmp);
	}

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

		for(int j = 0; j < s[i].size(); j++) {
			if(s[i][j] == '0') {
				fill(count.begin(), count.end(), 0);
				continue;
			}

			if(j == 0) {
				fill(count.begin(), count.end(), 0);
				ans.push_back(' ');
			} else if(s[i][j - 1] == '0' && s[i][j] != '0') {
				fill(count.begin(), count.end(), 0);
				ans.push_back(' ');
			}

			ans[ans.size() - 1] = keitai[s[i][j] - '0' - 1][count[s[i][j] - '0' - 1] % keitai[s[i][j] - '0' - 1].size()];
			count[s[i][j] - '0' - 1]++;
		}

		cout << ans << endl;
	}
}

C++: #include<iostream>

using namespace std;

int main()
{
  int ab;
  cin>>ab;

  for(;ab--;)
    {
      string s;
      cin>>s;
      char x;
      int count=0;
      bool out=true;
      for(int i=0;i<s.size();i++)
	{
	  if(s[i]!='0')
	    count++;
	    
	  if(s[i]=='1')
	    {
	      string t=".,!? ";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else
	      x=t[count%t.size()-1];
	    }
	  if(s[i]=='2')
	    {
	      string t="abc";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else
	      x=t[count%t.size()-1];
	    }
	  if(s[i]=='3')
	    {
	      string t="def";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else

	      x=t[count%t.size()-1];
	    }
	  if(s[i]=='4')
	    {
	      string t="ghi";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else
	      x=t[count%t.size()-1];
	    }

	  if(s[i]=='5')
	    {
	      string t="jkl";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else
	      x=t[count%t.size()-1];
	    }
	  if(s[i]=='6')
	    {
	      string t="mno";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else
	      x=t[count%t.size()-1];
	    }
	  if(s[i]=='7')
	    {
	      string t="pqrs";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else
	      x=t[count%t.size()-1];
	    }
	  if(s[i]=='8')
	    {
	      string t="tuv";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else
	      x=t[count%t.size()-1];
	    }
	  if(s[i]=='9')
	    {
	      string t="wxyz";
	      if(count%t.size()==0)
		x=t[t.size()-1];
	      else
	      x=t[count%t.size()-1];
	    }
	  if(s[i]=='0')
	    {
	      if(count!=0)
		{
		  cout<<x;
		  out=false;
		}
	      count=0;

	    }
	}
      if(!out)
      cout<<endl;
    } 

}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<char, vector<char>> input;
	input['1'] = {'.', ',', '!', '?', ' '};
	input['2'] = {'a', 'b', 'c'};
	input['3'] = {'d', 'e', 'f'};
	input['4'] = {'g', 'h', 'i'};
	input['5'] = {'j', 'k', 'l'};
	input['6'] = {'m', 'n', 'o'};
	input['7'] = {'p', 'q', 'r', 's'};
	input['8'] = {'t', 'u', 'v'};
	input['9'] = {'w', 'x', 'y', 'z'};
	rep (i, n) {
		string s;
		cin >> s;
		string ans;
		int idx = [&] {
			rep (i, s.size()) {
				if (s[i] != '0') return i; 
			}
			return 0;
		}();
		int cnt = -1;
		REP (i, idx, s.size()) {
			if (i != 0 && s[i] == '0' && s[i - 1] != '0') {
				ans += input[s[i - 1]][cnt];
				cnt = -1;
			} else if (s[i] != '0') {
				cnt = (cnt + 1) % input[s[i]].size();
			}
		}
		cout << ans << endl;
	}
	return 0;
}