import sys from decimal import Decimal, getcontext, ROUND_FLOOR getcontext().prec = 1000 # Sufficient precision to handle large exponents getcontext().rounding = ROUND_FLOOR # Round down for truncation def solve(): input = sys.stdin.read().split() n = int(input[0]) idx = 1 for _ in range(n): a = int(input[idx]) b = int(input[idx + 1]) idx += 2 # Calculate log10(a) with high precision log_a = Decimal(a).ln() log_10 = Decimal(10).ln() log10_a = log_a / log_10 log_val = log10_a * Decimal(b) # Determine Z by flooring the log value z = int(log_val.to_integral_exact()) # Uses current rounding mode (FLOOR) # Calculate the fractional part of the log value frac = log_val - z # Compute 10^frac and truncate to one decimal place pow_frac = Decimal(10) ** frac pow_rounded = pow_frac.quantize(Decimal('0.1')) # Split into integer and fractional parts to get X and Y parts = str(pow_rounded).split('.') x = int(parts[0]) if len(parts) == 1: y = 0 else: y = int(parts[1][0]) # First decimal digit print(f"{x} {y} {z}") if __name__ == "__main__": solve()