n = int(input()) from math import log from bisect import bisect_left res = [-1.0] + [log(i/10,10) for i in range(1,101)] #print(res) for _ in range(n): a,b = map(int,input().split()) c = b*log(a,10) z = int(c) idx = bisect_left(res, c-z) - 1 if idx < 1: idx = 1 if idx >= 100: idx = 99 x = idx//10 y = idx%10 print(x,y,z)