Problem: For a number X, let its "Coolness" be defined as the number of "101"s occurring in its binary representation. For example, the number 21 has Coolness 2, since its binary representation is 101012, and the string "101" occurs twice in this representation. 

A number is defined as Very Cool if its Coolness is greater than or equal to K.  Please, output the number of Very Cool integers between 1 and R. 

Input: 
The first line contains an integer T, the number of test cases. 
The next T lines contains two space-separated integers, R and K. 

Output: 
Output T lines, the answer for each test case. 

Constraints: 
1 ≤ T ≤ 100

1 ≤ R ≤ 10^5 
1 ≤ K ≤ 100

SAMPLE INPUT
1
5 1

SAMPLE OUTPUT
1

Solution (in PYTHON):

Solution:
import re
t=input()
def cool(n):
	#num=n
	l=''
	while n!=0:
		l+=str(n%2)
		n=n/2
	#l=l[::-1]
	#print num,l
	
	return len( re.findall( r'(?=(101))' , l ) )

flag=1
while t>0:
	r,k=raw_input().split()
	r=int(r)
	k=int(k)
	
	if flag==1:
		lastR=r
		flag=0
	else:
		if lastR==r and flag==0:
			print count
			t=t-1
			continue
			
	count=0
	x=5
	while x<=r:
		if cool(x)>=k:
			count+=1
		x+=1	
	print count
	t=t-1