#MATL, 20 bytes

	tVtnw48-PZ}t0<?x_]vs
	
[**Try it Online**](http://matl.tryitonline.net/#code=dFZ0bnc0OC1QWn10MDw_eF9ddnM&input=OTk)

[All test cases](http://matl.tryitonline.net/#code=YGkKdFZ0bnc0OC1QWn10MDw_eF9ddnMKRFRd&input=ODc5MDEKMTIzCjk5CjUKMQowCi0zCi0xMjMKLTkwMAotODc5MDE)