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

package main

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

// 標準入力を取得するScannerのインスタンスを作成
var scanner = bufio.NewScanner(os.Stdin)

// 標準入力で各行を読み込みstringとして返す
func readLine() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func main() {
	// 1: . , ! ? (スペース)
	// 2: a b c
	// 3: d e f
	// 4: g h i
	// 5: j k l
	// 6: m n o
	// 7: p q r s
	// 8: t u v
	// 9: w x y z
	// 0: 確定ボタン

	// 改行から空白区切りに変更
	scanner.Split(bufio.ScanWords)
	line, _ := strconv.Atoi(readLine()) // 5行標準入力が続く

	table := []string{
		"",      // 0 index調整ためダミーデータ
		".,!? ", // 1
		"abc",   // 2
		"def",   // 3
		"ghi",   // 4
		"jkl",   // 5
		"mno",   // 6
		"pqrs",  // 7
		"tuv",   // 8
		"wxyz"}  // 9

	// 5行分の標準入力を格納するsliceを作成する
	messages := make([]string, 0, line)

	// sliceに標準入力の内容を格納する
	for i := 0; i < line; i++ {
		messages = append(messages, readLine()) // messages=[20 220 222220 44033055505550666011011111090666077705550301110 000555555550000330000444000080000200004440000]
	}

	// 各行毎に解析する
	for _, message := range messages { // message=000555555550000330000444000080000200004440000
		// 0で分割する
		messageSlice := strings.Split(message, "0") // messageSlice=[   55555555    33    444    8    2    444    ]
		for _, word := range messageSlice {
			if word == "" {
				// NOP.
				// 0をセパレーターにしているので空文字がsliceに格納されてい箇所がある
				// 何もしない
			} else { // word=55555555
				// 一文字取り出しコード値をASCII文字に変換する
				ascii := string((word[0])) // word[0]=5

				// ASCII文字からintへ変換する(tableのindexになる)
				number, _ := strconv.Atoi(ascii)

				// 入力回数をカウントする
				count := len(word) // 5

				// 同じ数字を続けて入力すると変化する文字はループすることを考慮する
				for count > len(table[number]) { // 5 > 3
					count -= len(table[number]) // 2
				}

				// キー配列
				keys := table[number]                   //jkl
				fmt.Printf("%s", string(keys[count-1])) //k
			}
		}
		fmt.Println() // 改行
	}
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  ll n;
  cin >> n;
  rep(i,n){
    cin >> s;
    ll cnt = 0,num = 0;
    bool f = false;
    string ans = "";
    rep(j,s.size()){
      if(!f && s[j] != '0'){
        num = s[j] - '0' - 1;
        cnt = 0;
        f = true;
      }
      else{
        if(s[j] == '0'){
          if(f)
            ans += code[num][cnt];
          f = false;
        }
        else{
          ++cnt;
          cnt %= code[num].size();
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<stdlib.h>
#include<vector>

using namespace std;

int main(){
  int n,cnt=0;
  string s,before="",tmp,key;
  vector<string> keys{".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    if (s.length()==1) {
      cout << endl;
      continue;
    }
    for(int i=0;i<s.length();i++){
      tmp = s[i];
      if (tmp!="0" && tmp==before) cnt++;
      else if (tmp==before) continue;
      else if (tmp=="0"){
        key = keys[atoi(before.c_str())-1][(cnt-1)%(keys[atoi(before.c_str())-1].length())];
        cout << key;
        cnt=0;
        before="0";
      } else {
        before =tmp;
        cnt++;
      } 
    }
    cout << endl;
    
  }
  return 0;
    
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
	int n, i, j, k, c, d, x, a;
	char s[1025], r[76], t[10][6] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> s;
		for (j = x = a = 0, d = 0; j < strlen(s); j++, d = c)
		{
			c = s[j] - '0';
			if (c == 0 && d != 0)
				r[a] = t[d-1][x%strlen(t[d-1])], a++;
			else if (d == c)
				x++;
			else
				x = 0;
		}
		r[a] = '\0';
		cout << r << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<string> v = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv",
                        "wxyz"};
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        string ans;
        while(cur < s.size()){
            while(s[cur] != '0'){
                int cur2 = cur;
                while(s[cur] == s[cur2+1]) cur2++;
                ans += v[s[cur]-'1'][(cur2-cur)%v[s[cur]-'1'].size()];
                cur = cur2+1;
            }
            cur++;
        }
        cout << ans << "\n";
    }
    return 0;
}

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

using namespace std;

int main()
{
    string messages[9]= {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string msg;
        string output = "";
        int count = 0;
        char buf;

        cin >> msg;

        for (int j = 0; j < (int)msg.size(); j++) {
            char c = msg[j];

            if (c == '0' && j != 0) {
                if (buf == '1') {
                    output += messages[0][(count-1) % 5];
                } else if (buf == '2') {
                    output += messages[1][(count-1) % 3];
                } else if (buf == '3') {
                    output += messages[2][(count-1) % 3];
                } else if (buf == '4') {
                    output += messages[3][(count-1) % 3];
                } else if (buf == '5') {
                    output += messages[4][(count-1) % 3];
                } else if (buf == '6') {
                    output += messages[5][(count-1) % 3];
                } else if (buf == '7') {
                    output += messages[6][(count-1) % 4];
                } else if (buf == '8') {
                    output += messages[7][(count-1) % 3];
                } else if (buf == '9') {
                    output += messages[8][(count-1) % 4];
                }
                count = 0;
                buf = '0';
            } else {
                count++;
                buf = msg[j];
            }
        }
        cout << output << endl;
    }

    return 0;
}