import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.Scanner; /** * Created by sorin on 23.03.2017. */ public class prog { public static void main(final String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); String[] s = br.readLine().split(" "); StringBuilder sb = new StringBuilder(); int n = Integer.parseInt(s[0]); for (int i = 0; i < n; i++) { String[] hexes = br.readLine().split(" "); for (int j = 0; j < hexes.length; j++) { sb.append(hexToShort(hexes[j])).append(" "); } sb.append(System.lineSeparator()); } System.out.println(sb.toString()); } private static String hexToShort(String hex) { if ( hex.length() == 4 ){ return hex; } if ( hex.charAt(0) == '#' ) { hex = hex.substring(1); } if ( hex.length() != 6 ) { return ""; } String r = hex.substring(0,2); String g = hex.substring(2,4); String b = hex.substring(4,6); return "#" + shortVal(r) + shortVal(g) + shortVal(b); } private static String shortVal(String c) { int ci = Integer.parseInt(c, 16); return Integer.toString((ci%17 > 7) ? (17+ci-ci%17) : (ci-ci%17), 16).substring(0,1).toUpperCase(); } }