from sys import stdin, stdout

t = input()
inp = stdin.readlines()
out = []

for line in inp:
    n, m = map(int, line.strip().split())
    if m == 0:
        out.append(str(0))
        continue
    x = m * (n + 1) * (n + 1)
    x += (2 * m - 1)
    x /= (2 * (m + 1))

    out.append(str(x))
stdout.write("\n".join(out))
