for _ in range(int(input())): x, y = map(int, input().split()) while True: if x & (1 << y) > 0: y += 1 else: break print(sum(1<