gets.to_i.times do a,b = gets.split.map(&:to_i) u = Math.log(a, 10)*b t = 10**(u-u.floor) q = b.to_f/Math.log(10, a) puts "#{t.to_i} #{((t-t.to_i)*10).to_i} #{q.to_i}" end