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>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

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

signed main() {
	int n;
	cin >> n;
	rep(i, 0, n) {
		string s, ans = "";
		cin >> s;
		int now = 0, cnt = 0;
		rep(i, 0, s.size()) {
			if (s[i] =='0') {
				if (now == 0) continue;
				cnt %= t[now].size();
				ans += t[now][cnt];
				now = 0;
				cnt = 0;
			}
			else if (now == 0) {
				now = s[i] - '0';
				cnt = 0;
			}
			else if (now == s[i] - '0') {
				cnt++;
			}
			//cout << i << " " << now << " " << cnt << endl;
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

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

int main(void){
	int n;
	cin >> n;
	rep(k,n){
		string L;
		cin >> L;
		int count = 0;
		for(int i = 0; i < L.size(); i++){
			if(L[i] == '0'){
				if(count == 0)continue;
				int type = L[i-1]-'0';
				if(L[i] != '0')cout << s[type][(count-1)%s[type].size()];
				count = 0;
				continue;
			}
		}
		cout << endl;
	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

C++: #include<iostream>

using namespace std;

string str;

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

void solve() {
    cin>>str;
    char c = '\0';
    int cnt=-1;
    int num=0;

    for(int i=0;i<str.size();i++) {
        
        if(str[i]=='0') {
            if(cnt==-1) c='\0';
            else c=keys[num-1][cnt];
            if(c!='\0') cout<<(c);
            c='\0';
            cnt=-1;
            num=0;
        }
        else {
            num=str[i]-'0';
            cnt++;
            cnt%=keys[num-1].size();            
        }
    }
    cout<<endl;
}

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

    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string btn[10]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
typedef pair<int,int> P;
int main(){
	string in;
	for(cin>>in;cin>>in;){
		string res;
		P b=P(0,0);
		for(int i=0;i<(int)in.size();i++){
			if(b.first==0&&in[i]>'0'){
				b.first=in[i]-'0';b.second=0;
			}else if(b.first==in[i]-'0'){
				b.second++;
			}else if(in[i]=='0'&&b.first>0){
				res+=btn[b.first][b.second%btn[b.first].size()];
				b=P(0,0);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
int i;
cin>>i;
int 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{
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){
      cout<<'.';
    }
    else if(n1==2){
      cout<<',';
    }
    else if(n1==3){
      cout<<'!';
    }
    else{
      cout<<'?';
    }
    n1=0;
  }
  else if(n2){
    if(n2==1){
      cout<<'a';
    }
    else if(n2==2){
      cout<<'b';
    }
    else{
      cout<<'c';
    }
    n2=0;
  }
  else if(n3){
    if(n3==1){
      cout<<'d';
    }
    else if(n3==2){
      cout<<'e';
    }
    else{
      cout<<'f';
    }
    n3=0;
  }
  else if(n4){
    if(n4==1){
      cout<<'g';
    }
    else if(n4==2){
      cout<<'h';
    }
    else{
      cout<<'i';
    }
    n4=0;
  }
  else if(n5){
    if(n5==1){
      cout<<'j';
    }
    else if(n5==2){
      cout<<'k';
    }
    else{
      cout<<'l';
    }
    n5=0;
  }
  else if(n6){
    if(n6==1){
      cout<<'m';
    }
    else if(n6==2){
      cout<<'n';
    }
    else{
      cout<<'o';
    }
    n6=0;
  }
  else if(n7){
    if(n7==1){
      cout<<'p';
    }
    else if(n7==2){
      cout<<'q';
    }
    else if(n7==3){
      cout<<'r';
    }
    else{
      cout<<'s';
    }
    n7=0;
  }
  else if(n8){
    if(n8==1){
      cout<<'t';
    }
    else if(n8==2){
      cout<<'u';
    }
    else{
      cout<<'v';
    }
    n8=0;
  }
  else if(n9){
    if(n9==1){
      cout<<'w';
    }
    else if(n9==2){
      cout<<'x';
    }
    else if(n9==3){
      cout<<'y';
    }
    else{
      cout<<'z';
    }
    n9=0;
  }
}
}while(cin>>n);
}
}