import math n=int(raw_input()) while n>0: s=raw_input() l=s.split(" ") r=math.factorial(int(l[0])) print str(r).count(l[1]) n-=1
过不了,应该是什么地方没有注意到。