raw = $stdin.readlines

square = Array.new((150**2) * 2)

for height in 1..149
  for width in (height + 1)..150
    posit = height**2 + width**2
    if square[posit] == nil
      square[posit] = height * 1000 + width
    elsif square[posit] > height * 1000 + width
      square[posit] = height * 1000 + width
    end
  end
end

for i in 0..1000
  puts square[i].to_s()
end

for line in raw 

  stnum = line.split(" ")
  inp_h = stnum[0].to_i()
  inp_w = stnum[1].to_i()

  if inp_h * inp_w == 0
    #do nothing
  else
    catch(:exit) {
    for i in (inp_h**2 + inp_w**2)..(2*(150**2))
      if square[i] != nil
        puts ((square[i]/1000).to_i()).to_s() + " " + (square[i] - (square[i]/1000).to_i()*1000).to_s()
        throw :exit
      end
    end
    }
  end
end