import java.io.*;
import java.util.*;
import java.lang.*;
public class Codechef {
	PrintWriter out;
    StringTokenizer st;
    BufferedReader br;
 	
 	class Pair implements Comparable<Pair>
	{
	    int f;
	    int s;
 
	    Pair(int t, int r) {
	       f = t;
	       s = r;
	    }
	    public int compareTo(Pair p)
	    {
	    	if(this.f!=p.f)
	    		return this.f-p.f;

	    	return this.s-p.s;
	    }
 	}
 
	String ns() {
        while (st == null || !st.hasMoreElements()) {
 
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    String nextLine() throws Exception {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            throw new Exception(e.toString());
        }
        return str;
    }
 
    int nextInt() {
        return Integer.parseInt(ns());
    }
 
    long nextLong() {
        return Long.parseLong(ns());
    }
 
    double nextDouble() {
        return Double.parseDouble(ns());
    }
	
	int upperBound(int a[],int key) //on sorted array
	{
		int l=0,r=a.length-1;
		int ans=-1;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(a[mid]<key)
				l=mid+1;
			else
			{
				ans=a[mid];
				r=mid-1;
			}
		}
		return ans;
	}
	
	void solve() throws IOException{
		int t=nextInt();
		while(t-->0)
		{
			long n=nextLong();
			long m=nextLong();//no. of symbol as 1
			long ans=n*(n+1)/2;
			long q=(n-m)/(m+1);
			long r=(n-m)%(m+1);
			ans-=(m+1-r)*q*(q+1)/2;
			ans-=r*(q+1)*(q+2)/2;
			
			out.println(ans);
		}

 	}

    void run() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
		solve();
		out.flush();
		out.close();
	}

	public static void main(String args[]) throws IOException {
		new Codechef().run();
	}
  
}

