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:
def counter(n,k):
    if n<5:
        return 0
    binary = bin(n)[2:]
    count = 0
    for i in xrange(len(binary)-2):
        if binary[i:i+3] == "101":
            count += 1
    if count >= k:
        return 1
    else:
        return 0

for t in xrange(input()):
    r,k = map(int, raw_input().split())
    tot = 0
    #from pdb import set_trace
    #set_trace()
    for i in xrange(5,r+1):
        tot = tot+counter(i,k)
    print tot