import java.util.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(calc(sc.nextInt(), sc.nextInt())).append("\n"); } System.out.print(sb); } static String calc(double a, int b) { BigNumber org = new BigNumber(a); int[] base = new int[31]; BigNumber[] arr = new BigNumber[31]; base[0] = 1; arr[0] = org; for (int i = 1; i < 31; i++) { base[i] = base[i - 1] * 2; arr[i] = arr[i - 1].pow(); } BigNumber ans = new BigNumber(1.0); for (int i = 30; i >= 0; i--) { if (b >= base[i]) { ans = ans.mul(arr[i]); b -= base[i]; } } int x = (int)(ans.x); int y = (int)(ans.x * 10) % 10; StringBuilder sb = new StringBuilder(); return sb.append(x).append(" ").append(y).append(" ").append(ans.count).toString(); } static class BigNumber { double x; long count; public BigNumber(double a) { x = a; while (x >= 10) { x /= 10; count++; } } public BigNumber(double x, long count) { this.x = x; this.count = count; } public BigNumber pow() { double y = x * x; long next = count * 2; while (y >= 10) { y /= 10; next++; } return new BigNumber(y, next); } public BigNumber mul(BigNumber another) { double y = x * another.x; long next = count + another.count; while (y >= 10) { y /= 10; next++; } return new BigNumber(y, next); } } }