#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(0);
int tt;
cin >> tt;
while(tt--)
{
int n,k,mx=0,g=0;
cin >> n>>k;
if(k<n)
cout << 0 << endl;
else if(1+n==k)
{
cout << ((n*(n+1))/2)/k<<endl;
}
else
{
n++;
if(1+n==k)
cout << ((n*(n+1))/2)/k<<endl;
else
cout << 0 << endl;
}
}
return 0;
}