package com.thinker.bishi.xiaomi;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author lzh
 */
public class FenSheng {
    private static int len = 10;
    private static String[] key = new String[]{"ZERO", "ONE", "TWO", "THREE", "FOUR",
            "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"};
    private static int[] model = new int[len];
    private static void init(){
        for (int i=0;i<len;i++){
            model[(i+8)%10] = i;
        }
    }
    public static void main(String[] args) {
        init();
        Scanner in = new Scanner(System.in);
        int size = Integer.parseInt(in.nextLine());
        while (size > 0){
            String tmp = in.nextLine();
            while (tmp != null){
                for(int i=0;i<len;i++){
                    int index = tmp.indexOf(key[i]);
                    if(index != -1) {
                        System.out.print(model[i]);
                        if(tmp.length() == key[i].length()){
                            tmp = null;
                            break;
                        }else {
                            tmp = tmp.substring(key[i].length());
                        }
                    }
                }
            }
            size--;
            System.out.println();
        }
    }
}
