

import java.util.Scanner;


public class OneSeg {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    while(t--!=0) {
      long n = sc.nextLong();
      long m = sc.nextLong();
      long zero = n-m;
      long div = m+1;
      if(div>=zero) {
        n = (n*(n+1))/2;
        System.out.println(n-zero);
        continue;
      }
      long l = 0;
      long r = (long)1e10;
      long ans = 0;
      while(l<=r) {
        long mid = (l+r)/2;
        if(mid*div>=zero) {
          ans = mid;
          r = mid-1;
        } else {
          l = mid+1;
        }
      }
      //System.out.println(ans);
      if(ans*div>zero) {
        div--;
        long rest = zero-div*ans;
        ans = (ans*(ans+1))/2;
        ans *= div;
        ans += (rest*(rest+1))/2;
        ans = (n*(n+1))/2-ans;
        System.out.println(ans);
      } else {
        ans = (ans*(ans+1))/2;
        ans *= div;
        ans = (n*(n+1))/2-ans;
        System.out.println(ans);
      }
    }
  }

}
