import sys from decimal import Decimal, getcontext, ROUND_FLOOR def main(): input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 # Set high precision to handle large exponents accurately getcontext().prec = 35 getcontext().rounding = ROUND_FLOOR results = [] for _ in range(N): A = int(input[idx]) B = int(input[idx + 1]) idx += 2 a = Decimal(A) log10_a = a.ln() / Decimal(10).ln() log_val = log10_a * Decimal(B) # Compute k and fractional part f k = log_val.to_integral() f = log_val - k # Calculate leading = 10^f leading = Decimal(10) ** f # Determine X and Y X = leading.to_integral() shifted = leading * Decimal(10) shifted_floor = shifted.to_integral() Y = shifted_floor % 10 # Convert k to integer for Z Z = int(k) results.append(f"{X} {Y} {Z}") print('\n'.join(results)) if __name__ == "__main__": main()