ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2025. Line Fighting

Time limit: 1.0 second
Memory limit: 64 MB
Boxing, karate, sambo… The audience is sick of classic combat sports. That is why a popular sports channel launches a new competition format based on the traditional Russian entertainment called line fighting. There can be from 2 to k teams taking part in a competition, and there are n fighters altogether in all the teams. Before the competition starts, the fighters are divided into teams: each fighter becomes a member of exactly one team. Two fighters fight each other if they are members of different teams. The organizers believe that the more the number of fights between fighters, the higher the popularity of a competition will be. Help the organizers to distribute fighters between teams so as to maximize the number of fights and output this number.

Input

The first line contains the number of tests T (1 ≤ T ≤ 10). In each of the following T lines you are given a test: integers n and k separated with a space (2 ≤ kn ≤ 104).

Output

For each test output the answer (one integer) in a separate line.

Sample

inputoutput
3
6 3
5 5
4 2
12
10
4
Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2014