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 <bits/stdc++.h>
using namespace std;

int main(){

  int n, cnt = 0, num = 0;
  string str, phone;

  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> phone;
    for(int j = 0; j < (int)phone.size(); j++){
      if(phone[j] == '1'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 5){
	  case 0: 
	    cout << " ";
	    break;
	  case 4: 
	    cout << '?';
	    break;
	  case 3: 
	    cout << '!';
	    break;
	  case 2: 
	    cout << ',';
	    break;
	  case 1: 
	    cout << '.';
	    break;
	  }
	  cnt = 0;
	}
      }else if(phone[j] == '2'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 3){
	  case 0: 
	    cout << 'c';
	    break;
	  case 2: 
	    cout << 'b';
	    break;
	  case 1: 
	    cout << 'a';
	    break;
	  }
	  cnt = 0;
	}
      }else if(phone[j] == '3'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 3){
	  case 0: 
	    cout << 'f';
	    break;
	  case 2: 
	    cout << 'e';
	    break;
	  case 1: 
	    cout << 'd';
	    break;
	  }
	  cnt = 0;
	}
      }else if(phone[j] == '4'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 3){
	  case 0: 
	    cout << 'i';
	    break;
	  case 2: 
	    cout << 'h';
	    break;
	  case 1: 
	    cout << 'g';
	    break;
	  }
	  cnt = 0;
	}
      }else if(phone[j] == '5'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 3){
	  case 0: 
	    cout << 'l';
	    break;
	  case 2: 
	    cout << 'k';
	    break;
	  case 1: 
	    cout << 'j';
	    break;
	  }
	  cnt = 0;
	}
      }else if(phone[j] == '6'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 3){
	  case 0: 
	    cout << 'o';
	    break;
	  case 2: 
	    cout << 'n';
	    break;
	  case 1: 
	    cout << 'm';
	    break;
	  }
	  cnt = 0;
	}
      }else if(phone[j] == '7'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 4){
	  case 0: 
	    cout << 's';
	    break;
	  case 3: 
	    cout << 'r';
	    break;
	  case 2: 
	    cout << 'q';
	    break;
	  case 1: 
	    cout << 'p';
	    break;
	  }
	  cnt = 0;
	}
      }else if(phone[j] == '8'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 3){
	  case 0: 
	    cout << 'v';
	    break;
	  case 2: 
	    cout << 'u';
	    break;
	  case 1: 
	    cout << 't';
	    break;
	  }
	  cnt = 0;
	}
      }else if(phone[j] == '9'){
	cnt++;
	if(phone[j+1] == '0'){
	  switch (cnt % 4){
	  case 0: 
	    cout << 'z';
	    break;
	  case 3: 
	    cout << 'y';
	    break;
	  case 2: 
	    cout << 'x';
	    break;
	  case 1: 
	    cout << 'w';
	    break;
	  }
	  cnt = 0;
	}
      }
    }
    cout << endl;
  }









return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    string inp;
    int n;
    cin >> n;
    while(n--){
        cin >> inp;
            inp.append(1, '0');
        bool head = true;
        char headNum;
        int count;
        for(int i = 0; inp[i]; i++){
            if((inp[i - 1] == '0' && inp[i] == '0') || (i == 0 && inp[i] == '0')) continue;
            if(head){
                headNum = inp[i];
                count = 0;
                head = false;
            }
            if(headNum == inp[i] && headNum != '0'){
                count++;
            }else{
                char outp;
                if(headNum == '1'){
                    count %= 5;
                    if(count == 0) count = 5;
                    if(count == 1) outp = '.';
                    else if(count == 2) outp =',';
                    else if(count == 3) outp ='!';
                    else if(count == 4) outp ='?';
                    else if(count == 5) outp =' ';
                }else if(headNum >= '2' && headNum <= '6'){
                    count %= 3;
                    if(count == 0) count = 3;
                    outp = 'a' - 1 + count + (headNum - '2') * 3;
                }else if(headNum == '7'){
                    count %= 4;
                    if(count == 0) count = 4;
                    outp = 'p' - 1 + count;
                }else if(headNum == '8'){
                    count %= 3;
                    if(count == 0) count = 3;
                    outp = 't' - 1 + count;
                }else if(headNum == '9'){
                    count %= 4;
                    if(count == 0) count = 4;
                    outp = 'w' - 1 + count;
                }
                cout.put(outp);

                if(inp[i] - '0'){
                    i--;
                }
                head = true;
                continue;
            }
        }
        cout << endl;
    }
}