def ch_to_array l
	l1 = []
	l.each_char{|x|l1 << x.to_i}

	l1
end

def place_set l, p
	ret = []
	ar = ch_to_array l
	num = p.to_i - ar.length

	num.times{|x| ret << "0" }
	ret.concat ch_to_array l

	return ret.join
end

def minimize l, flag = false
	ret = ch_to_array l
	ret.sort!

	if flag
		return ret
	else
		return ret.join
	end
end

def maximize l
	ret = minimize l, true
	ret.reverse!

	return ret.join
end

def findit l, db
	db.each{|x|
		result, index = x

		if result == l
			return l, index + 1
		end
	}

	return nil
end

def getans x
	db = [[]]
	index = 0
	inp, p = x


	loop {
		pls = place_set db.length < 2 ? inp : db[index][0].to_s, p
		max = maximize pls
		min = minimize pls
		a = (max.to_i - min.to_i).to_i
		f = findit a, db

		elem, id = f

		if f != nil
			puts "#{index + (id < 1 ?  0 : 1) - id} #{elem} #{id}"

			return
		end

		db << [a, index]

		index += 1
	}
end

ARGV.each_slice(2).each{|x|
	getans x
}

# p = "6"
# inp = "83268"
# p = "4"
# inp = "2012"
# p = "4"
# inp = "1112"
# p = "0"
# inp = "1"
# db = [[]]
# index = 0
# 0.upto(10) {
	# pls = place_set db.length < 2 ? inp : db[index][0].to_s, p

	# max = maximize pls
	# min = minimize pls
	# a = (max.to_i - min.to_i).to_i
	# f = findit a, db
	
	# hoge, piyo = f
		
	# puts "max: #{max}, min: #{min}, a: #{a}, id: #{piyo}"

	# if f != nil
		# puts "#{index + piyo < 1 ?  0 : 1 - piyo}  #{hoge}, #{piyo}"

		# exit
	# end

	# db << [a, index]

	# index += 1
# }

# puts minimize place_set "0", "1"