def zero_to_five(ride, stop)
	print ride
	if ride < stop
		do_the_print(ride+1,stop)
	else
		do_the_print_d(ride-1,stop)
	end
end

def six_to_nine(ride, stop)
	print ride
	if ride < stop
		do_the_print(ride+1,stop)
	elsif 6 <= stop && stop <= 9
		if ride == 9
			do_the_print(5,stop)
		else
			do_the_print(ride+1,9)
			do_the_print_d(5,stop)
		end
	else
		if ride == 9
			do_the_print_d(5,stop)
		else
			do_the_print(ride+1,9)
			do_the_print_d(5,stop)
		end
	end
end


def do_the_print(ride,stop)
	(ride).upto(stop).each { |i| print " "+i.to_s }
end

def do_the_print_d(ride,stop)
	(ride).downto(stop).each { |i| print " "+i.to_s }
end

gets.to_i.times do
	ride_stop = gets
	ride = ride_stop[0].to_i
	stop = ride_stop[2].to_i
	ride <= 5 ? zero_to_five(ride, stop) : six_to_nine(ride, stop)
	puts ""
end