Go: // Keitai Message
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2006&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	for i := 0; i < n; i++ {
		message := nextString(sc)
		currentButton, count := 0, 0
		for _, word := range message {
			// 確定の処理を書く
			if word == '0' {
				if currentButton == 0 {
					count = 0
					continue
				}
				mod := len(table[currentButton])
				tmp := table[currentButton][(count-1)%mod]
				currentButton, count = 0, 0
				fmt.Printf("%c", tmp)
			} else {
				count++
				currentButton = int(word) - 48 // '0'はASCIIで48
			}
		}
		fmt.Println()
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


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



int main(){
	int n;
	string s;
	cin>>n;
	rep(i,n){
		cin>>s;
		string a;
		rep(j,s.size()){
			if(s[j]!='0'){
				char c=t[s[j]-'0'][0];
				int k=0;
				while(1){
					j++;
					if(j>s.size())break;
					if(s[j]=='0'){
						a+=c;
						break;
					}
					k=(k+1)%t[s[j]-'0'].size();
					c=t[s[j]-'0'][k];
				}
			}
		}
		cout<<a<<endl;
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
 
using namespace std;
 
const int INF = (1<<30) - 1;
 
string table[] = {
    "",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
     
    int T;
    cin >> T;
    string in;
    while(T--){
        cin >> in;
        int i = 0;
        int n = in.length();
         
        while(i<n){
            int s = i;
            while(i<n && in[i]!='0'){
                i++;
            }
            if(0<i && in[i-1]-'0'!=0){
                string st = table[in[i-1]-'0'];
                cout << st[(i-s-1)%st.length()];
            }
            i++;
        }
        cout << endl;
    }
     
    return 0;
}

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

using namespace std;


int main(){
    vector<string> k{".,!? ", "abc", "def",
                     "ghi"  , "jkl", "mno",
                     "pqrs" , "tuv", "wxyz"};
    int n;
    cin >> n; cin.ignore();
    while(n--){
        string line;
        getline(cin, line);
        int button = -1, push = -1;
        for(char c: line){
            if(c == '0'){
                if(button == -1)continue;
                cout << k[button][push % (int)k[button].size()];
                button = push = -1;
            }
            else{
                button = c - '1';
                push++;
            }
        }
        cout << '\n';
    }
    return 0;
}

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

using namespace std;

vector<vector<char> > data;

string parse(string msg){
  string res = "";
  int state = 0;
  int time = 0;
  for(auto c : msg){
    if(c == '0'){
      if(time % data[state-1].size() == 0){
        res += data[state-1][data[state-1].size() - 1];
      }else{
        res += data[state-1][time % data[state-1].size() - 1];
      }
      time = 0;
    }else{
      int num = c - '0';
      if(state != num){
        state = num;
        time = 1;
      }else{
        time++;
      }
    }
  }
  return res;
}

void init(){
  data.push_back({'.',',','!','?',' '});
  data.push_back({'a','b','c'});
  data.push_back({'d','e','f'});
  data.push_back({'g','h','i'});
  data.push_back({'j','k','l'});
  data.push_back({'m','n','o'});
  data.push_back({'p','q','r','s'});
  data.push_back({'t','u','v'});
  data.push_back({'w','x','y','z'});
}

int main(){
  int n;
  string msg;
  init();
  cin >> n;
  for(int i=0;i<n;i++){
    cin>> msg;
    cout << parse( msg ) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;

int loopCount(const int button, const int count) {
    if (button == 1) {
        return (count - 1) % 5;
    } else if (button == 7 || button == 9) {
        return (count - 1) % 4;
    }
    return (count - 1) % 3;
}

int main() {
    const char keitaiChar[][6] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz",};
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string input;
        cin >> input;
        int preButton = 0, count = 0;
        for (string::iterator it = input.begin(); it < input.end(); it++) {
            int button = *it - '0';
            if (button == 0) {
                if (preButton != 0) {
                    cout << keitaiChar[preButton - 1][loopCount(preButton, count)];
                    count = 0;
                }
            } else {
                count++;
            }
            preButton = button;
        }
        cout << endl;
    }
}

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

using namespace std;

vector<string>split(string s){
  vector<string>res;
  int pre = 0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      res.push_back(s.substr(pre,i-pre));
      pre = i+1;
    }
  }
  return res;
}

int main(void){

  map<char,string>mp;
  mp['0']="";
  mp['1']=".,!?";
  mp['2']="abc";
  mp['3']="def";
  mp['4']="ghi";
  mp['5']="jkl";
  mp['6']="mno";
  mp['7']="pqrs";
  mp['8']="tuv";
  mp['9']="wxyz";
  
  int n;
  cin >> n;

  while(n--){
    string s;
    cin >> s;
    vector<string>res = split(s);
    for(int i=0;i<res.size();i++)
      cout << mp[res[i][0]][(res[i].size()-1)%max(1,(int)mp[res[i][0]].size())];
    cout << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<bitset>
#include<map>
using namespace std;

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


string s;
bool input(){
  s="";
  if(!(cin>>s)){
    return false;
  }

  return true;
}


string solve(){
  string res = "";
  int n=-1;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      if(n==-1||i==0)continue;
      int tmp = s[i-1]-'0';
      res += list[tmp-1][n%list[tmp].size()];
      n=-1;
    }else{
      n++;
    }
  }
  return res;
}

int main(){
  int c;
  cin>>c;
  for(int i=0;i<c;i++){
    input();
    string ans = solve();
    if(ans.size()!=0)cout<<ans<<endl;
  }
}