Pranav just learned about Modulus(%) and trying to solve a problem on Modulus but he always get TLE. Your task is to help him. Problem is simple, you have been given two numbers A and M and you have to find A%M and print it. 

Input Format

Firstline: T, where T is the number of test cases. Now T line followed, Where each line consist of A and M space separated. 

Constraints :

1 ≤T ≤ 100

Number of digit in A ≤ 5×10^5

1 ≤ M ≤ 10^9

Output Format

Print A%M in a new line.

Sample Input

2

12344 12

12 123 

Sample Output

8

12

NOTE Only C/C++ is allowed for this challenge.

SAMPLE INPUT
2
12344 12
12 123

SAMPLE OUTPUT
8
12
t=int(raw_input())
while t>0:
    m,n=map(int,raw_input().split())
    print(m%n)
    t-=1