n = int(input())
for i in range(0, n) :
  nums = (input().split(" "))
  if ('8' in nums[1]) or ('9' in nums[1]) :
    print(nums[0], 0, int(nums[1]), int(nums[1], 16))
  else :
    print(nums[0], int(nums[1], 8), int(nums[1]), int(nums[1], 16))
