// Arup Guha
// 1/27/22
// Solution to 2016 GNYR Problem A: Which Base is it Anyway?

import java.util.*;

public class base {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=1; loop<=nC; loop++) {
		
			int dummy = stdin.nextInt();
			char[] n = stdin.next().toCharArray();
			int intVal = Integer.parseInt(new String(n));
			
			// Set up accumulators.
			int oct = 0, hex = 0;
			boolean badOct = false;
			
			// Base conversion.
			for (int i=0; i<n.length; i++) {
				
				// Update.
				oct = 8*oct + (n[i]-'0');
				hex = 16*hex + (n[i]-'0');
				
				// Oops, can't do octal.
				if (n[i] >= '8') badOct = true;
			}
			
			// Update this.
			if (badOct) oct = 0;
			
			// Ta da!
			System.out.println(loop+" "+oct+" "+intVal+" "+hex);
		}
	}
}