#d1605. Ayoub's function

Ayoub's function

Ayoub's Function

Problem Description

Define the function f(s)f(s), where ss is a 01 string, as the number of substrings of ss that contain at least one 1.

You are given a string ss with length nn and exactly mm 1s. Find the maximum possible value of f(s)f(s).

Input Format

The input consists of multiple test cases.

The first line contains an integer TT (1≤T≤1051 \le T \le 10^5), the number of test cases.

Each of the next TT lines contains two integers n,mn, m (1≤n≤1091 \le n \le 10^9, 0≤m≤n0 \le m \le n).

Output Format

Output TT lines, each containing one integer: the answer.

Sample Input

5
3 1
3 2
3 3
4 0
5 2

Sample Output

4
5
6
0
12

Sample Explanation

First test case: when s=010s = \texttt{010}, f(s)=4f(s) = 4.

Second test case: when s=101s = \texttt{101}, f(s)=5f(s) = 5.

Third test case: when s=111s = \texttt{111}, f(s)=6f(s) = 6.

Fourth test case: when s=0000s = \texttt{0000}, f(s)=0f(s) = 0.

Fifth test case: when s=01010s = \texttt{01010}, f(s)=12f(s) = 12.