<reponame>shinkeonkim/today-ps
for i in range(int(input())):
    a,b=list(map(int,input().split()))
    n=a//b
    print(n*(n+1)//2 + n*(n-1)//2)
for i in range(int(input())):
    a,b=list(map(int,input().split()))
    n=a//b
    print(n*(n+1)//2 + n*(n-1)//2)