import java.io.BufferedReader; import java.io.InputStreamReader; public class No219 { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new InputStreamReader( System.in)); double[] logarithmTable = createLogarithmTable(); int N = Integer.parseInt(br.readLine()); for (int i = 0; i < N; i++) { String[] a = br.readLine().split(" "); double A = Double.parseDouble(a[0]); double B = Double.parseDouble(a[1]); double ans = B * Math.log10(A); int Z = (int) Math.floor(ans); double decimalPart = ans - Z; int high = 100; int low = 10; int mid = 0; while (low < high) { mid = (high + low) / 2; if (decimalPart == logarithmTable[mid]) { break; } else if (decimalPart < logarithmTable[mid]) { high = mid; } else { low = mid + 1; } } double XY = mid * 0.1; int X = (int) Math.floor(XY); int Y = (int) ((XY - X) * 10); System.out.println(X + " " + Y + " " + Z); } } catch (Exception e) { System.err.println("Error:" + e.getMessage()); } } // static double[][] createLogarithmTable() { // double[][] logarithmTable = new double[10][10]; // for (int i = 1; i < 10; i++) { // for (int j = 0; j < 10; j++) { // logarithmTable[i][j] = Math.log10(i + j * 0.1); // } // } // return logarithmTable; // } static double[] createLogarithmTable() { double[] logarithmTable = new double[100]; for (int i = 10; i < 100; i++) { logarithmTable[i] = Math.log10(i * 0.1); } return logarithmTable; } }