The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by sum of some numbers which are prime. Chef wrote those numbers in dairy. Cheffina came and saw what the chef was doing. Cheffina immediately closed chef's dairy and for testing chef's memory, she starts asking numbers and chef needs to answer wheater given number N can be formed by the sum of K prime numbers if it yes then print 1 else print 0. 
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow. 
- Each test case contains a single line of input, two integers $N, K$.
-----Output:-----
For each test case, output in a single line answer as 1 or 0.
-----Constraints-----
- $1 \leq T \leq 10^5$
- $2 \leq N \leq 10^5$
- $1 \leq K \leq 10^5$
-----Sample Input:-----
2
12 2
11 2
-----Sample Output:-----
1
0
# cook your dish here
from random  import randint
def prime(n):      #Fermat Little's theorem
    if n<4:
        return n==2 or n==3
    for i in range(5):
        a=randint(2,n-2)
        if pow(a,n-1,n)!=1:
            return False
    return True

def solve(n, k):
    if n<2*k:
        return (0)
    elif k==1:
        if prime(n):
            return (1)
        else:
            return (0) 
    elif k==2:
        if n&1:
            if prime(n-2):
                return (1)
            else:
                return (0)
        else:
            return (1)
    else:
        return (1)
for t_itr in range(int(input())):
    n,k=list(map(int, input().split()))
    print(solve(n,k))

# cook your dish here
from random  import randint
def prime(n):      #Fermat Little's theorem
    if n<4:
        return n==2 or n==3
    for i in range(5):
        a=randint(2,n-2)
        if pow(a,n-1,n)!=1:
            return False
    return True

def solve(n, k):
    if n<2*k:
        return (0)
    elif k==1:
        if prime(n):
            return (1)
        else:
            return (0) 
    elif k==2:
        if n&1:
            if prime(n-2):
                return (1)
            else:
                return (0)
        else:
            return (1)
    else:
        return (1)
for t_itr in range(int(input())):
    n,k=list(map(int, input().split()))
    print(solve(n,k))
