import java.util.Scanner; public class Main_yukicoder219 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { long a = sc.nextLong(); long b = sc.nextLong(); long loop = b; double x = a; long xlg = 0; while (x >= 10) { x /= 10; xlg++; } double xy = 1.0; long xylg = 0; while (loop > 0) { if (loop % 2 == 1) { xy = xy * x; xylg += xlg; } x = x * x; xlg += xlg; while (x >= 10) { x /= 10; xlg++; } loop /= 2; } while (xy >= 100) { xy /= 10; xylg++; } while (xy < 10) { xy *= 10; xylg--; } System.out.println((int)(xy / 10) + " " + (int)xy % 10 + " " + (xylg + 1)); } sc.close(); } }