Sum of Numerators
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

You are given 2 integers n and k, and there are n fractions as follows:

Please reduce each fraction to its simplest form and calculate the sum of the numerators.
A fraction is in simplest form if and only if , where denotes the greatest common divisor (GCD) of integers a and b. For example, the simplest form of is , and the simplest form of is .

输入描述:

The first line contains an integer  --- the number of test cases.
Each test case consists of one line containing 2 integers and .

输出描述:

For each test case, output an integer in a line.
示例1

输入

复制
2
5 0
5 1

输出

复制
15
12

说明

In the second test case of the sample, the simplest form of the 5 fractions is as follows:
\frac{1}{2}, \frac{1}{1}, \frac{3}{2}, \frac{2}{1}, \frac{5}{2}
The sum of numerators is 1+1+3+2+5=12.