import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] base = new int[31]; base[0] = 1; for (int i = 1; i < base.length; i++) { base[i] = base[i - 1] * 2; } StringBuilder sb = new StringBuilder(); for (int j = 0; j < n; j++) { String[] line = br.readLine().split(" ", 2); int a = Integer.parseInt(line[0]); int b = Integer.parseInt(line[1]); int[] values = new int[32]; long[] counts = new long[32]; values[0] = a; for (int i = 0; i < 31; i++) { while (values[i] >= 100000) { values[i] /= 10; counts[i]++; } values[i + 1] = values[i] * values[i]; counts[i + 1] = counts[i] * 2; } int ans = 1; long size = 0; for (int i = 30; i >= 0; i--) { if (b >= base[i]) { ans *= values[i]; size += counts[i]; while (ans >= 100000) { ans /= 10; size++; } b -= base[i]; } } while (ans >= 100) { ans /= 10; size++; } int x; int y; if (ans < 10) { x = ans; y = 0; } else { x = ans / 10; y = ans % 10; size++; } sb.append(x).append(" ").append(y).append(" ").append(size).append("\n"); } System.out.print(sb); } }