#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define  FIFO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define  inf 2e18
#define  mod 1000000007
#define  bg begin()
#define  en end()
#define  ll long long int
#define  pb push_back
#define  mpx make_pair
#define  pii pair<int,int>
#define  pll pair<ll,ll>
#define  vi vector<int>
#define  vll vector<long long int>
#define  vpll vector<pair<long long int,long long int> >
#define  vpii vector<pair<int,int> >
#define  vstr vector<string>
#define  mpii map<int ,int>
#define  max3(a,b,c) max(a,max(b,c))
#define  min3(a,b,c) min(a,min(b,c))
#define  setbits(x) __builtin_popcountll(x)
#define  zerobits(x) __builtinctzll(x) //zeros after rightmost set bit
#define  w(t) ll t; cin>>t; while(t--)
#define  vin(v,m) for(int i=0;i<m;i++){ll x;cin>>x; v.pb(x);}
#define  for0(i,m) for(int i=0;i<m;i++)
#define  for1(i,m) for(int i=1;i<=m;i++)
#define  forn(i,a,b) for(int i=a;i<=b;i++)
#define  forv(it,v) for(auto it=v.begin();it!=v.end();it++)
#define  mem(a,val) memset(a,val,sizeof(a))
#define  Sort(vec) sort(vec.begin(),vec.end())
#define  RSort(vec) sort(vec.rbegin(),vec.rend())
#define  eb emplace_back
#define  bs binary_search
#define  lb(v,a) lower_bound(v.begin(),v.end(),a)
#define  ub(v,a) upper_bound(v.begin(),v.end(),a)
#define  deb1(x) cerr<<#x<<": "<<x<<" "<<endl
#define  deb2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define  deb3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define  deb4(a, b, c, dxx) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#dxx<<": "<<dxx<<endl
#define  FF first
#define  SS second
#define  yes "YES"
#define  no "NO"
#define  PI 3.141592653589793238462643383279502884L
#define  printv(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" "
// find_by_order(p)  returns iterator to kth element starting from 0;
// order_of_key(p) returns count of elements strictly smaller than p;
//order of key returns the index if the element was present.(If not present)
template <typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll Ceil(ll a, ll b) {return a / b + (a % b != 0);}
ll Logn(ll m, ll r) {return (m > r - 1) ? 1 + Logn(m / r, r) : 0;}
ll fastModExp(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1; } return res;}
ll GCD(ll a, ll b) { if (b == 0)return a; else  return GCD(b, a % b);}
//Chrnlgy: Binary Search,Greedy,dp,dfs and similar
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}
void OJ()
{
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.in", "w", stdout);
#endif
    FIFO;
}

struct Comp {
    bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
        if (a.first != b.first) {
            return a.first < b.first;
        }
        return a.second > b.second;
    }
};

int main()
{
    OJ();
    w(t) {
        ll n, m;
        cin >> n >> m;
        if (m == 0)
        {
            cout << 0 << endl;
        }
        else if (m == n)
        {
            cout << n*(n + 1) / 2 << endl;
        }
        else
        {
            if (n - m <= m)
            {
                cout << n*(n + 1) / 2 - (n - m) << endl;
            }
            else
            {
                ll r = n - 2 * m;
                cout << n*(n + 1) / 2 - (m) - r*(r + 1) / 2 << endl;
            }
        }
    }

    return 0;
}