Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.

Your house has $n$ rooms. In the $i$-th room you can install at most $c_i$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $k$ sections is equal to $k^2$ burles.

Since rooms can have different sizes, you calculated that you need at least $sum_i$ sections in total in the $i$-th room. 

For each room calculate the minimum cost to install at most $c_i$ radiators with total number of sections not less than $sum_i$.


-----Input-----

The first line contains single integer $n$ ($1 \le n \le 1000$) — the number of rooms.

Each of the next $n$ lines contains the description of some room. The $i$-th line contains two integers $c_i$ and $sum_i$ ($1 \le c_i, sum_i \le 10^4$) — the maximum number of radiators and the minimum total number of sections in the $i$-th room, respectively.


-----Output-----

For each room print one integer — the minimum possible cost to install at most $c_i$ radiators with total number of sections not less than $sum_i$.


-----Example-----
Input
4
1 10000
10000 1
2 6
4 6

Output
100000000
1
18
10



-----Note-----

In the first room, you can install only one radiator, so it's optimal to use the radiator with $sum_1$ sections. The cost of the radiator is equal to $(10^4)^2 = 10^8$.

In the second room, you can install up to $10^4$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.

In the third room, there $7$ variants to install radiators: $[6, 0]$, $[5, 1]$, $[4, 2]$, $[3, 3]$, $[2, 4]$, $[1, 5]$, $[0, 6]$. The optimal variant is $[3, 3]$ and it costs $3^2+ 3^2 = 18$.

Difficulty: EASY

Solutions:
for case in range(int(input())):
	(c, s) = [int(x) for x in input().split()]
	mn = s // c
	c2 = 0
	if mn != 0:
		c2 = s % c
	else:
		c2 = s
	c -= c2
	ans = c2 * (mn + 1) * (mn + 1) + c * mn * mn
	print(ans)


n = int(input())
for i in range(n):
	(c, s) = list(map(int, input().split()))
	a = s // c
	b = s % c
	res = 0
	res += a ** 2 * (c - b)
	res += (a + 1) ** 2 * b
	print(res)


for i in range(int(input())):
	(c, s) = map(int, input().split())
	div = s // c
	print(s % c * (2 * div + 1) + c * div * div)


n = int(input())
for i in range(n):
	(c, sumi) = map(int, input().split())
	a = sumi // c
	b = a + 1
	print(int(b ** 2 * (sumi % c) + a ** 2 * (c - sumi % c)))


for _ in ' ' * int(input()):
	(a, b) = map(int, input().split())
	s = 0
	z = b // a
	z1 = b % a
	s += (z + 1) ** 2 * z1
	a -= z1
	s += z ** 2 * a
	print(s)


n = int(input())
for i in range(n):
	(c, sum) = map(int, input().split())
	k = int(sum / c)
	r = sum - k * c
	print((c - r) * k * k + r * (k + 1) * (k + 1))


n = int(input())
while n:
	sum = 0
	(a, b) = map(int, input().split())
	if a == 1:
		print(b ** 2)
	elif a > b:
		print(b)
	else:
		z = b // a + 1
		x = z - 1
		m = b % a
		r = a - m
		sum += m * z ** 2
		sum += r * x ** 2
		print(sum)
	n -= 1


n = int(input())
for _ in range(n):
	(c, sum) = map(int, input().split())
	x = [sum // c for _ in range(c)]
	for i in range(sum % c):
		x[i] += 1
	ans = 0
	for y in x:
		ans += y ** 2
	print(ans)


n = int(input())
for i in range(n):
	(rad, sec) = map(int, input().split())
	divisor = sec // rad
	rem = sec % rad
	min_sum = rem * (divisor + 1) ** 2 + (rad - rem) * divisor ** 2
	print(min_sum)


t = int(input())
while t:
	t -= 1
	(c, s) = map(int, input().split())
	a = s // c
	b = s % c
	ans = 0
	for i in range(0, c - b):
		ans += int(a * a)
	for i in range(c - b, c):
		ans += int((a + 1) * (a + 1))
	print(ans)


n = int(input())
for _ in range(n):
	(c, su) = map(int, input().split())
	ci = [0] * c
	while su > 0:
		for i in range(c):
			if su > 0:
				ci[i] += 1
				su -= 1
			else:
				break
	to = 0
	for i in range(c):
		to += ci[i] ** 2
	print(to)


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	(c, sm) = map(int, ip().split())
	v = sm // c
	r = sm % c
	print(r * (v + 1) ** 2 + (c - r) * v ** 2)


n = int(input())
for ccc in range(n):
	(c, s) = list(map(int, input().split()))
	x = s // c
	y = s - x * c
	print(y * (x + 1) ** 2 + (c - y) * x ** 2)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print((a - b % a) * (b // a) ** 2 + b % a * math.ceil(b / a) ** 2)


n = int(input())
while n != 0:
	lista = input().split(' ')
	n1 = int(lista[0])
	n2 = int(lista[1])
	if n2 % n1 == 0:
		a = int(n2 / n1)
		print(a ** 2 * n1)
	else:
		x = n2 // n1
		b = n2 % n1
		soma1 = x ** 2 * (n1 - b)
		soma2 = (x + 1) ** 2 * b
		print(soma1 + soma2)
	n -= 1


for i in range(int(input())):
	(c, sumi) = [int(x) for x in input().split()]
	deg = sumi // c
	res = (deg + 1) ** 2 * (sumi % c) + (c - sumi % c) * deg ** 2
	print(res)


for q in range(int(input())):
	(a, b) = map(int, input().split())
	if b % a == 0:
		print(a * (b // a) ** 2)
	else:
		r = b % a
		print((a - r) * (b // a) ** 2 + r * (1 + b // a) ** 2)


n = int(input())
ans = []
for _ in range(n):
	(a, b) = map(int, input().split())
	bi = b % a
	sm = a - bi
	ans.append(bi * (b // a + 1) ** 2 + sm * (b // a) ** 2)
for x in ans:
	print(x)


nb = input().split()
for i in range(int(nb[0])):
	tmp = input().split()
	c = int(tmp[0])
	sumi = int(tmp[1])
	if sumi < c:
		print(sumi)
	elif sumi % c == 0:
		print(int(sumi / c * (sumi / c) * c))
	else:
		sumic = pow(int(sumi / c), 2)
		sumicc = pow(1 + int(sumi / c), 2)
		print(int(sumic * (c - sumi % c)) + (c - (c - sumi % c)) * sumicc)


for i in int(input()) * [0]:
	(a, b) = map(int, input().split())
	c = b // a
	d = b % a
	print(d * (b // a + 1) ** 2 + abs(a - d) * c ** 2)


n = int(input())
for i in range(n):
	entrada = input().split(' ')
	ci = int(entrada[0])
	sumi = int(entrada[1])
	med = sumi % ci
	if med == 0:
		print((sumi // ci) ** 2 * ci)
	else:
		aux = sumi % ci
		aux2 = sumi // ci
		if ci > sumi:
			print(sumi)
		else:
			aux3 = aux2 ** 2 * (ci - aux)
			s = (aux2 + 1) ** 2 * aux + aux3
			print(s)


t = int(input())
for _ in range(t):
	(c, m) = map(int, input().split())
	x = m // c
	y = m % c
	print(x * x * (c - y) + (x + 1) * (x + 1) * y)


from math import gcd, ceil
from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def pred(n, k, pointer):
	return pointer - k >= n

def yes():
	print('YES')

def no():
	print('NO')
Testcase = inin()
for n in range(Testcase):
	(ci, sumi) = inar()
	layers = sumi // ci
	h = sumi % ci
	l = ci - h
	su = l * layers ** 2
	su += h * (layers + 1) ** 2
	print(su)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	exc = s % c
	pas = s // c
	t = 0
	for j in range(c):
		if exc > 0:
			t += (pas + 1) ** 2
			exc -= 1
		else:
			t += pas ** 2
	print(t)


import math
for _ in range(int(input())):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
	else:
		ele1 = math.floor(s / c)
		ele2 = math.ceil(s / c)
		print(s % c * ele2 ** 2 + ele1 ** 2 * (c - s % c))


n = int(input())
for i in range(n):
	(c, sm) = map(int, input().split())
	k = sm // c
	if sm % c == 0:
		print(c * k ** 2)
	else:
		print((sm - k * c) * (k + 1) ** 2 + (c - (sm - k * c)) * k ** 2)


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	base = s // c
	add = s % c
	ans = base ** 2 * (c - add) + (base + 1) ** 2 * add
	print(ans)


from math import *
n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
	elif s % c == 0:
		q1 = s // c
		ans = q1 ** 2
		ans = ans * c
		print(ans)
	else:
		q1 = s // c
		q2 = s // c + 1
		r = s % c
		c = c - r
		ans = q1 ** 2 * c + q2 ** 2 * r
		print(ans)


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	if a == 1:
		print(b ** 2)
	elif a >= b:
		print(b)
	elif b % a == 0:
		print(a * (b // a) ** 2)
	else:
		q = b // a
		rem = b % a
		sum1 = rem * (q + 1) ** 2 + (a - rem) * q ** 2
		print(sum1)


t = int(input())
import math
for j in range(t):
	(c, s) = list(map(int, input().split()))
	x = math.ceil(s / c)
	y = math.floor(s / c)
	summ = 0
	for i in range(s % c):
		summ += x * x
	for i in range(c - s % c):
		summ += y * y
	print(summ)


import math
n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	ans = math.ceil(y / x)
	cnt = 0
	final = 0
	while y % x != 0:
		if y == 0:
			break
		cnt += 1
		x -= 1
		y -= ans
	if y != 0:
		final += (y // x) ** 2 * x
	final += ans ** 2 * cnt
	print(final)


t = int(input())
for _ in range(t):
	(c, s) = list(map(int, input().split()))
	cc = (c - s % c) * (s // c) ** 2 + s % c * (s // c + 1) ** 2
	print(cc)


def main():
	n = int(input())
	for i in range(n):
		(a, b) = [int(v) for v in input().split()]
		v = b // a
		if b % a == 0:
			print(v * v * a)
		else:
			d = a - b % a
			print(v * v * d + (v + 1) * (v + 1) * (b % a))
main()


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	c = b // a
	d = b % a
	print(d * (c + 1) ** 2 + (a - d) * c ** 2)


for _ in range(int(input())):
	(r, s) = map(int, input().split())
	x = s // r
	y = s % r
	ans = y * (x + 1) ** 2 + (r - y) * x ** 2
	print(ans)


n = int(input())
for i in range(n):
	(c, b) = list(map(int, input().split()))
	a = b // c
	b -= a * c
	ans = 0
	for j in range(c):
		if b == 0:
			ans += a * a
		else:
			ans += (a + 1) * (a + 1)
			b -= 1
	print(ans)


def calc(radiator: int, section: int):
	if radiator == 1:
		return pow(section, 2)
	elif section == 1:
		return 1
	ans: int = 0
	sec: int = section
	for i in reversed(range(1, radiator + 1)):
		x = sec // i
		sec -= x
		ans += pow(x, 2)
	return ans

def main():
	n: int = int(input())
	for _ in range(n):
		(radiator, section) = map(int, input().split())
		ans: int = calc(radiator, section)
		print(ans)
main()


n = int(input())
for i in range(n):
	(ci, sumi) = map(int, input().split())
	mini = int(sumi / ci)
	out = ci * (mini * mini)
	modu = sumi % ci
	out = out - modu * (mini * mini) + modu * (mini + 1) * (mini + 1)
	print(out)


def sec(total, needed):
	if total >= needed:
		return needed
	k = needed // total
	needed = needed - k * total
	ans = needed * (k + 1) ** 2 + (total - needed) * k ** 2
	return ans
n = int(input())
ans = []
for i in range(n):
	(total, needed) = [int(i) for i in input().split()]
	ans.append(sec(total, needed))
for i in ans:
	print(i)


from sys import *
t = int(stdin.readline())
for _ in range(t):
	(n, s) = map(int, stdin.readline().split())
	if s <= n:
		print(s)
	else:
		a = [0] * n
		j = 0
		for i in range(s):
			if j == n:
				j = 0
			a[j] += 1
			j += 1
		ans = 0
		for i in range(n):
			ans += a[i] * a[i]
		print(ans)


t = int(input())
for rep in range(0, t):
	(c, s) = input().split()
	c = int(c)
	s = int(s)
	mic = s // c
	mare = s // c + 1
	cntMic = c
	cntMare = 0
	maiTrebuie = s % c
	cntMare += maiTrebuie
	cntMic -= maiTrebuie
	print(cntMic * mic * mic + cntMare * mare * mare)


import math
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	summ = math.ceil(b / a) ** 2 * (b % a)
	summ += (a - b % a) * math.trunc(b / a) ** 2
	print(summ)


n = int(input())
summ = 0
div = 0
mod = 0
for num in range(n):
	ck = [int(i) for i in input().split()]
	if ck[1] % ck[0] == 0:
		summ = (ck[1] // ck[0]) ** 2 * ck[0]
	elif ck[1] // ck[0] == 0:
		summ = ck[1]
	else:
		div = ck[1] // ck[0]
		mod = ck[1] % ck[0]
		summ = (div + 1) ** 2 * mod + div ** 2 * (ck[0] - mod)
	print(summ)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(c, s) = value()
	ans = inf
	for i in range(1, c + 1):
		each = s // i
		a = each + 1
		b = each
		here = a * a * (s % i) + b * b * (i - s % i)
		ans = min(here, ans)
	print(ans)


import math
n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	K = 0
	r = s % c
	q = s // c
	if q == 0:
		K = r
	else:
		K += r * (1 + q) ** 2
		K += (c - r) * q ** 2
	print(K)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	len2 = y % x
	len1 = x - len2
	val = y // x
	print(val ** 2 * len1 + (val + 1) ** 2 * len2)


t = int(input())
for _ in range(t):
	(c, s) = map(int, input().split())
	k = (s // c) ** 2 * (c - s % c)
	h = (s // c + 1) ** 2 * (s % c)
	print(k + h)


import math
t = int(input())
for _ in range(t):
	(c, k) = map(int, input().split())
	ones = k // c
	fin = ones * ones * (c - k % c)
	twos = k % c * (k // c + 1) * (k // c + 1)
	print(fin + twos)


rooms = input()
for i in range(int(rooms)):
	(r, s) = input().split(' ')
	r = int(r)
	s = int(s)
	cost = 0
	if r == 1:
		print(s ** 2)
	elif r < s:
		s_remaining = s - r * (s // r)
		sr = s // r
		cost += sr ** 2 * (r - s_remaining)
		srOne = sr + 1
		cost += srOne ** 2 * s_remaining
		print(cost)
	else:
		print(s)
exit()


def main():
	t = int(input())
	for i in range(t):
		solve()

def solve():
	(n, total) = list(map(int, input().split(' ')))
	remainder = total % n
	value = (total // n + 1) ** 2 * remainder + (n - remainder) * (total // n) ** 2
	print(value)
main()


import sys
import math

def rl():
	return sys.stdin.readline().strip()

def rn():
	return list(map(int, sys.stdin.readline().strip().split()))

def rnn():
	return map(int, sys.stdin.readline().strip().split())

def rln(n):
	l = [None] * n
	for i in range(n):
		l[i] = int(rl())
	return l
tc = int(input())
for _ in range(tc):
	(c, sum) = rnn()
	q = sum // c
	r = sum % c
	res = 0
	if c < sum:
		res = (c - r) * q * q + r * (q + 1) * (q + 1)
	else:
		res = sum
	print(res)


import math
n = int(input())
s = 0
for i in range(n):
	(c, sumi) = map(int, input().split(' '))
	x = math.floor(sumi / c) ** 2
	x1 = sumi % c
	print(x1 * math.ceil(sumi / c) ** 2 + x * (c - x1))


import math

def calc_cost(ar):
	max_heaters = ar[0]
	min_total_sections = ar[1]
	if max_heaters >= min_total_sections:
		print(min_total_sections)
		return
	x = {}
	while min_total_sections > max_heaters:
		k = int(min_total_sections / max_heaters)
		min_total_sections -= k * max_heaters
		x[max_heaters] = k
	s = (max_heaters - min_total_sections) * x[max_heaters] ** 2 + min_total_sections * (x[max_heaters] + 1) ** 2
	print(s)
t = int(input().strip())
for i in range(t):
	ar = list(map(int, input().strip().split()))
	calc_cost(ar)


n = int(input())
for p in range(n):
	entrada = input().split(' ')
	c = int(entrada[0])
	s = int(entrada[1])
	r = s % c
	if r == 0:
		print((s // c) ** 2 * c)
	else:
		r = s % c
		d = s // c
		if c > s:
			print(s)
		else:
			f = d ** 2 * (c - r)
			soma = (d + 1) ** 2 * r + f
			print(soma)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	(q, r) = divmod(s, c)
	ans = (q + 1) ** 2 * r + q ** 2 * (c - r)
	print(ans)


n = int(input())
k = [0]
for i in range(n):
	inputString = input()
	a = inputString.split()
	sec = int(a[0])
	size = int(a[1])
	secSize = size // sec
	countBig = size % sec
	leastPrice = countBig * (secSize + 1) ** 2 + (sec - countBig) * secSize ** 2
	k.append(int(leastPrice))
k.pop(0)
for q in range(n):
	print(k[q])


from collections import defaultdict
t = int(input())
while t > 0:
	(a, b) = [int(i) for i in input().split()]
	if a == 1 or b == 1:
		ans = b ** 2
	else:
		curr = b // a
		rem = b % a
		temp = curr - rem
		s = a - rem
		ans = s * curr ** 2 + rem * (curr + 1) ** 2
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	(c, s) = map(int, input().split())
	u = s // c
	v = u + 1
	cv = s % c
	cu = c - cv
	print(u ** 2 * cu + v ** 2 * cv)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(x, y) = (b // a, b % a)
	print((a - y) * x ** 2 + y * (x + 1) ** 2)


for _ in range(int(input())):
	cetak = 0
	(n, k) = map(int, input().split())
	ini = k // n
	itu = k % n
	cetak += (n - itu) * ini ** 2 + itu * (ini + 1) ** 2
	print(cetak)


n = int(input())
for i in range(n):
	(c, sum) = map(int, input().split())
	k = sum // c
	cnt1 = sum % c
	cnt2 = c - cnt1
	print(cnt1 * (k + 1) ** 2 + cnt2 * k ** 2)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	ans = (b // a + 1) ** 2 * (b % a) + (b // a) ** 2 * (a - b % a)
	print(ans)


for i in range(int(input())):
	(c, sections) = map(int, input().split())
	x = sections // c
	if sections * c == sections:
		print(x * x * c)
	else:
		temp = x + 1
		i = 1
		while x * (c - i) + temp * i != sections:
			i = i + 1
			if i == c:
				temp = temp + 1
				i = 0
		print(x * x * (c - i) + temp * temp * i)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	(x, y) = divmod(s, c)
	print((c - y) * x * x + y * (x + 1) ** 2)


for i in range(int(input())):
	(n, k) = [int(j) for j in input().split()]
	m = k // n
	d = k % n
	print(d * (m + 1) ** 2 + (n - d) * m ** 2)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
		continue
	ans = 0
	minimal = s // c
	additive = s % c
	ans = (c - additive) * minimal ** 2 + additive * (minimal + 1) ** 2
	print(ans)


def res(a, b):
	q = b // a
	r = b % a
	return (a - r) * q * q + r * (q + 1) ** 2
n = int(input())
L = []
for i in range(n):
	(a, b) = map(int, input().split())
	m = res(a, b)
	L.append(m)
for j in L:
	print(j)


n = int(input())
for _ in range(n):
	(i, s) = list(map(int, input().split()))
	if i >= s:
		print(s)
	elif s % i == 0:
		print((s // i) ** 2 * i)
	else:
		ost = s % i
		print((s // i) ** 2 * (i - ost) + (s // i + 1) ** 2 * ost)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	k = s // c
	r = s % c
	ans = (c - r) * k ** 2 + r * (k + 1) ** 2
	print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, m) = LI()
		k = m % n
		t = m // n
		r = t ** 2 * (n - k) + (t + 1) ** 2 * k
		rr.append(r)
	return JA(rr, '\n')
print(main())


n = int(input())
for _ in range(n):
	(ci, sumi) = list(map(int, input().split()))
	if sumi % ci == 0:
		print((sumi // ci) ** 2 * ci)
	elif sumi <= ci:
		print(sumi)
	else:
		cur = sumi // ci
		this_room = [cur for i in range(ci)]
		sumi = sumi - cur * ci
		for i in range(len(this_room)):
			if sumi <= 0:
				break
			else:
				this_room[i] += 1
				sumi -= 1
		ans = 0
		for i in this_room:
			ans += i * i
		print(ans)


def m(a, b):
	x = b // a
	ans = 0
	b = b % a
	for i in range(0, b):
		ans += (x + 1) ** 2
	for i in range(b, a):
		ans += x ** 2
	return ans
for itr in range(int(input())):
	(a, b) = map(int, input().split())
	print(m(a, b))


import math
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	s = 0
	s += (b // a + 1) ** 2 * (b % a)
	s += (b // a) ** 2 * (a - b % a)
	print(s)


n = int(input())
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	if a == 1:
		print(b ** 2)
	elif b == 1:
		print(1)
	else:
		x = int(b / a)
		print((b - a * x) * (x + 1) ** 2 + (a - b + a * x) * x ** 2)


n = int(input())
while n:
	n -= 1
	l = list(map(int, input().split()))
	(a, b) = (l[0], l[1])
	if a >= b:
		print(b)
	else:
		k = b // a
		v = b % a
		s = 0
		s += (a - v) * k ** 2 + v * (k + 1) ** 2
		print(s)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	ok = 0
	arr = [1] * s
	if c == 1:
		print(s ** 2)
	elif s == 1:
		print(1)
	else:
		arr = [s // c] * c
		for i in range(s - s // c * c):
			arr[i] += 1
		for j in arr:
			ok += j ** 2
		print(ok)


import sys
from math import *
import builtins
import string
alphabets = list(string.ascii_lowercase)
ALPHABETS = list(string.ascii_uppercase)

def print(x, end='\n'):
	sys.stdout.write(str(x) + end)

def get_int():
	return int(input())

def get_list_ints():
	return list(map(int, input().split()))

def get_char_list():
	s = input()
	return list(s[:len(s)])

def get_tuple_ints():
	return tuple(map(int, input().split()))

def print_iterable(p):
	print(' '.join(map(str, p)))

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return high

def main():
	p = get_int()
	for q in range(p):
		(n, k) = get_list_ints()
		c = k // n
		y = k - n * c
		x = n - y
		total = x * c * c + y * (c + 1) * (c + 1)
		print(total)
	pass
main()


for _ in range(int(input())):
	(c, summ) = map(int, input().split())
	a = summ // c
	b = summ % c
	print(b * (a + 1) ** 2 + (c - b) * a ** 2)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	t = [s // c] * c
	i = 0
	j = s % c
	while i < len(t) and j > 0:
		t[i] += 1
		j -= 1
		i += 1
	print(sum((i ** 2 for i in t)))


import math
t = int(input())
while t:
	(c, s) = map(int, input().split())
	k = s // c
	m = s % c
	print(k ** 2 * c + m * (1 + 2 * k))
	t -= 1


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
for _ in range(ii()):
	(a, b) = mi()
	x = b // a
	r = b % a
	print(r * (x + 1) * (x + 1) + (a - r) * x * x)


n = int(input())
for i in range(n):
	(c, sum) = input().split()
	(c, sum) = (int(c), int(sum))
	div = int(sum / c)
	rest = sum % c
	if rest == 0:
		print(c * div * div)
	else:
		print((c - rest) * (div * div) + rest * (div + 1) * (div + 1))


q = int(input())
for i in range(q):
	(x, y) = map(int, input().split(' '))
	c = y // x
	d = y % x
	sum = (c + 1) * (c + 1) * d + c * c * (x - d)
	print(sum)


n = int(input())
for i in range(n):
	(c, sumi) = map(int, input().split())
	ans = 0
	while sumi > 0:
		tmp = (sumi + c - 1) // c
		ans += tmp * tmp
		sumi -= tmp
		c -= 1
	print(ans)


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
n = oint()
for _ in range(n):
	(c, sum) = rint()
	a = sum // c
	b = sum % c
	print((a + 1) ** 2 * b + a ** 2 * (c - b))


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if a >= b:
		print(b)
	else:
		f = b // a
		m = b % a
		ans = m * (f + 1) ** 2 + f ** 2 * (a - m)
		print(ans)


import math
t = int(input())
while t > 0:
	t -= 1
	(c, x) = map(int, input().split())
	d = int(x / c)
	rem = x % c
	ans = rem * (d + 1) ** 2 + (c - rem) * d ** 2
	print(ans)


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	total = (s // c) ** 2 * (c - s % c) + (s // c + 1) ** 2 * (s % c)
	print(total)


n = int(input())
for i in range(n):
	(c, sum) = input().split()
	c = int(c)
	sum = int(sum)
	x = sum // c
	result = 0
	if sum % c == 0:
		result = x * x * c
	else:
		temp = sum - x * c
		result = (x + 1) * (x + 1) * temp + x * x * (c - temp)
	print(result)


n = int(input())
for _ in range(n):
	(total, s) = map(int, input().split())
	if s <= total:
		print(s)
	else:
		result = 0
		min_v = s // total
		rem_count = s % total
		result = rem_count * (min_v + 1) ** 2
		result += (total - rem_count) * min_v ** 2
		print(result)


import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
	(c, s) = [int(item) for item in input().split()]
	small_val = s // c
	large_val = small_val + 1
	large_num = s % c
	small_num = c - large_num
	ans = small_val ** 2 * small_num + large_val ** 2 * large_num
	print(ans)


import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
	(ci, si) = map(int, input().split())
	print(si % ci * (si // ci + 1) ** 2 + (ci - si % ci) * (si // ci) ** 2)


n = int(input())
for i in range(n):
	ans = 0
	(c, sum) = map(int, input().split())
	bas = sum // c
	rest = sum % c
	ans += (c - rest) * bas ** 2
	bas += 1
	ans += rest * bas ** 2
	print(ans)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x > y:
		print(y)
		continue
	a = y // x
	b = y % x
	x = x - b
	y = b
	print(a * a * x + (a + 1) * (a + 1) * y)


n = int(input())
for _ in range(n):
	(rads, secs) = map(int, input().split())
	if secs <= rads:
		print(secs)
	else:
		(base, rem) = divmod(secs, rads)
		print((rads - rem) * base ** 2 + rem * (base + 1) ** 2)


n = int(input())
for i in range(n):
	hello = list(map(int, input().split()))
	(c, s) = (hello[0], hello[1])
	print(s % c * (s // c + 1) ** 2 + (c - s % c) * (s // c) ** 2)


n = int(input())
for _ in range(n):
	(ci, si) = map(int, input().split())
	q = si // ci
	rem = si % ci
	print(rem * (q + 1) ** 2 + (ci - rem) * q ** 2)


import math
n = int(input())
while n > 0:
	n -= 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	ans = b % a * pow(math.floor(b / a) + 1, 2) + (a - b % a) * pow(math.floor(b / a), 2)
	print(ans)


N = int(input())
for _ in range(N):
	(a, b) = map(int, input().split())
	k = b // a
	l = b - k * a
	print(k * k * (a - l) + (k + 1) ** 2 * l)


n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	sq = b // a
	sq *= sq
	sq1 = b // a + 1
	sq1 *= sq1
	print((a - b % a) * sq + b % a * sq1)


line = input()
for i in range(int(line)):
	l = input().split()
	c = int(l[0])
	s = int(l[1])
	if c == 1:
		print(s * s)
	elif c > s:
		print(s)
	else:
		dif = s - c
		if dif < c:
			out = c - dif + 4 * dif
			print(out)
		elif dif == c:
			print(dif * 4)
		elif dif % c == 0:
			out = dif // c + 1
			print(out * out * c)
		else:
			out = dif // c + 1
			out2 = (c - dif % c) * out * out
			out3 = dif % c * (out + 1) * (out + 1)
			print(out2 + out3)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def xrange(n):
	return range(1, n + 1)
MOD = 10 ** 9 + 7
INF = 10 ** 20
I = lambda : list(map(int, input().split()))
from collections import defaultdict as dd
from math import gcd
import string
import heapq
(n,) = I()
for i in range(n):
	(c, s) = I()
	r = s % c
	print((c - r) * (s // c) ** 2 + r * (s // c + 1) ** 2)


import os
import sys

def main():
	N = read_int()
	for _ in range(N):
		print(solve(*read_ints()))

def solve(C, S):
	if C > S:
		return S
	l = S // C
	h = l + 1
	hc = S - l * C
	lc = C - hc
	return lc * l ** 2 + hc * h ** 2
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)
main()


n = int(input())
for i in range(n):
	(c, s) = [int(x) for x in input().split(' ')]
	ans = (c - s % c) * (s // c) ** 2 + s % c * (s // c + 1) ** 2
	print(ans)


n = int(input())
for i in range(n):
	ip = input()
	(c, s) = [int(num) for num in ip.split()]
	ans = (c - s % c) * (s // c) ** 2 + s % c * (s // c + 1) ** 2
	print(ans)


INF = 10 ** 10

def main():
	print = out.append
	(c, sum) = get_list()
	x = 0
	while x * c <= sum:
		x += 1
	res = c * (x - 1) ** 2
	res += (sum - (x - 1) * c) * (2 * x - 1)
	print(res)
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	d = s // c
	rem = s % c
	print(rem * (d + 1) * (d + 1) + (c - rem) * d * d)


for _ in [0] * int(input()):
	(c, s) = map(int, input().split())
	d = s // c
	print((c - s % c) * d * d + s % c * (d + 1) ** 2)


import math
n = int(input())
for j in range(n):
	(a, b) = list(map(int, input().split()))
	res = 0
	kd = math.floor(b / a)
	res += kd ** 2 * (a - b % a)
	res += (kd + 1) ** 2 * (b % a)
	print(res)


n = int(input())
for i in range(n):
	ls = [int(i) for i in input().split()]
	if ls[0] >= ls[1]:
		print(ls[1])
	elif ls[1] % ls[0] == 0:
		print(ls[0] * (ls[1] // ls[0]) * (ls[1] // ls[0]))
	else:
		p = ls[0] // 2 * (ls[1] // ls[0] + 1) + (ls[0] - ls[0] // 2) * (ls[1] // ls[0])
		q = ls[1] - p
		print((ls[0] // 2 + q) * (ls[1] // ls[0] + 1) * (ls[1] // ls[0] + 1) + (ls[0] - ls[0] // 2 - q) * (ls[1] // ls[0]) * (ls[1] // ls[0]))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	t = b // a
	c = b - a * t
	print(t * t * (a - c) + (t + 1) * (t + 1) * c)


def main():
	n = int(input())
	while n > 0:
		n -= 1
		f = [int(e) for e in input().split()]
		r = f[1] % f[0]
		c = int(f[1] / f[0])
		sm = (f[0] - r) * c ** 2 + r * (c + 1) ** 2
		print(sm)
	return 0
main()


t = int(input())
while t > 0:
	l = [int(x) for x in input().split()]
	a = l[0]
	b = l[1]
	if a == 1:
		print(b ** 2)
	elif b == 1:
		print(1)
	elif b % a == 0:
		print(a * (b // a) ** 2)
	else:
		print(b % a * (b // a + 1) ** 2 + (a - b % a) * (b // a) ** 2)
	t = t - 1


n = int(input())
for testcases in range(n):
	(c, s) = map(int, input().split())
	x = s // c
	y = s - s // c * c
	print(y * (x + 1) ** 2 + (c - y) * x ** 2)


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_str():
	return list(sys.stdin.readline().split())
N = inp()
for i in range(N):
	(c, S) = inpl()
	t1 = S // c
	t2 = t1 + 1
	ans = t1 ** 2 * (c - S % c) + t2 ** 2 * (S % c)
	print(ans)


n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	ans = 0
	num = c[i][1] // c[i][0]
	amari = c[i][1] % c[i][0]
	cnt = c[i][0]
	ans = (cnt - amari) * num ** 2 + amari * (num + 1) ** 2
	print(ans)


from sys import stdin
test = int(stdin.readline())
for i in range(test):
	(a, b) = map(int, stdin.readline().split(' '))
	if a >= b:
		print(b)
	elif b % a == 0:
		print(int((b / a) ** 2 * a))
	else:
		res = 0
		i = b // a
		ii = b % a
		res += (i + 1) ** 2 * ii + i ** 2 * (a - ii)
		print(int(res))


def f():
	a = input().split()
	c = int(a[0])
	s = int(a[1])
	m = s // c
	q = s % c
	print(m ** 2 * (c - q) + (m + 1) ** 2 * q)
n = int(input())
i = 0
while i < n:
	f()
	i += 1


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(1, 10)
	a = [random.randint(1, 10) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
t = I()
for _ in range(t):
	(c, s) = LI()
	a = s // c
	m = s - c * (s // c)
	an = a ** 2 * (c - m) + m * (a + 1) ** 2
	print(an)


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	x = s // c
	y = s // c + 1
	print((c - s % c) * x * x + s % c * y * y)


import math

def solve():
	(c, sm) = map(int, input().split())
	if sm <= c:
		print(sm)
	elif sm % c == 0:
		print(c * (sm // c) ** 2)
	else:
		cnt2 = sm % c
		cnt1 = c - cnt2
		print(cnt1 * (sm // c) ** 2 + cnt2 * math.ceil(sm / c) ** 2)
t = int(input())
for _ in range(t):
	solve()


from math import *
from sys import *
from heapq import *
from collections import defaultdict
from itertools import permutations
import os, sys
from io import IOBase, BytesIO
M = 10 ** 9 + 7

def graph_as_tree_1_root():
	n = int(input())
	dict = defaultdict(list)
	for _ in range(n - 1):
		(x, y) = list(map(int, input().split()))
		dict[x].append(y)
		dict[y].append(x)
	tree = [[1]]
	temp = [1]
	vall = 0
	seen = set([i for i in range(2, n + 1)])
	lol = []
	while len(seen) > 0:
		lol = list(seen)
		tt = []
		for x in temp:
			aa = []
			for val in dict[x]:
				if val in seen:
					aa += [val]
					seen.remove(val)
			dict[x] = aa
			tt += aa
		tree.append(tt)
		temp = tt
		vall += 1
	for x in lol:
		dict[x] = []
	print(tree, dict)

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b //= 2
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def alldivisors(n):
	list = []
	arr = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				arr += [i]
			else:
				arr += [i]
				list.append(n // i)
	arr += list[::-1]
	return arr

def primefactorisation(n):
	potentional_p = 3
	itog_list = defaultdict(int)
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			itog_list[n] += 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			itog_list[potentional_p] += 1
		potentional_p += 2
	return itog_list

def meth(a, b):
	lst = [b // a] * a
	b %= a
	for i in range(b):
		lst[i] += 1
	return lst

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = list(map(int, input().split()))
		x = b % a
		val = b // a
		sm = (val + 1) ** 2 * x + val ** 2 * (a - x)
		print(sm)
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
from math import ceil
for i in range(n):
	(c, sumi) = map(int, input().split())
	t = int(sumi / c)
	r = sumi % c
	print((t + 1) * r * (t + 1) + (c - r) * t * t)


t = int(input())
for c in range(t):
	ss = 0
	(a, b) = map(int, input().split())
	if b <= a:
		print(b)
	else:
		de = int(b / a)
		ss = de ** 2 * (a - b % a) + (de + 1) ** 2 * (b % a)
		print(ss)


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split(' '))
	if s == 1:
		print(1)
	elif c == 1:
		print(s ** 2)
	elif c >= s:
		print(s)
	else:
		ed = s // c
		m = s % c
		print((c - m) * ed ** 2 + m * (ed + 1) ** 2)


t = int(input())
for i in range(t):
	(max_radiators, min_sections) = map(int, input().split())
	rem = min_sections % max_radiators
	if rem == 0:
		print(int(max_radiators * pow(min_sections / max_radiators, 2)))
	elif rem == min_sections:
		print(min_sections)
	else:
		floor = min_sections // max_radiators
		buckets = [floor for i in range(max_radiators)]
		for i in range(rem):
			buckets[i] += 1
		sum = 0
		for i in buckets:
			sum += pow(i, 2)
		print(sum)


import math
n = int(input())
for i in range(n):
	(c, sum1) = map(int, input().split())
	x = sum1 % c
	res = (math.floor(sum1 / c) + 1) ** 2 * x
	res = res + math.floor(sum1 / c) ** 2 * (c - x)
	print(res)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
for _ in range(RI()):
	(max_radiators, min_sections) = RMI()
	(div, mod) = divmod(min_sections, max_radiators)
	print(div ** 2 * (max_radiators - mod) + (div + 1) ** 2 * mod)


for i in range(int(input())):
	(c, s) = map(int, input().split())
	q = s // c
	w = s % c
	print(c * q ** 2 + (2 * q + 1) * w)


n = int(input())
for i in range(n):
	(c, s) = list(map(int, input().split()))
	q = s // c
	r = s % c
	res = (c - r) * (q * q) + r * (q + 1) ** 2
	print(res)


tc = int(input())
for i in range(0, tc):
	s = str(input()).strip().split()
	n = int(s[0])
	sum = int(s[1])
	ans = sum % n * ((int(sum / n) + 1) * (int(sum / n) + 1)) + (n - sum % n) * (int(sum / n) * int(sum / n))
	print(int(ans))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	(k, l) = (b // a, b % a)
	print((a - l) * k ** 2 + l * (k + 1) ** 2)


for _ in range(int(input())):
	(c, sm) = map(int, input().split())
	ans = (sm // c + 1) ** 2 * (sm % c) + (sm // c) ** 2 * (c - sm % c)
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	rem = b % a
	print((a - rem) * (b // a) ** 2 + rem * (b // a + 1) ** 2)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b:
		print(b)
	else:
		cost = 0
		time = b // a
		left = b % a
		first = time + 1
		for i in range(left):
			cost = first * first * left
		more = a - left
		cost += time * time * more
		print(cost)


for _ in [0] * int(input()):
	(a, b) = map(int, input().split())
	(k, l) = (b // a, b % a)
	print((a - l) * k ** 2 + l * (k + 1) ** 2)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	rem = b % a
	div = b // a
	print(b % a * (1 + div) ** 2 + (a - b % a) * div ** 2)


for _ in range(int(input())):
	(c, total) = map(int, input().split())
	ans = 0
	if not c > total:
		lst = 1
		total -= c
		if total >= c:
			div = total // c
			lst = div + 1
			rem = total % c
			ans = (lst + 1) ** 2 * rem + lst ** 2 * (c - rem)
		else:
			rem = total
			ans = (lst + 1) ** 2 * rem + lst ** 2 * (c - rem)
		print(ans)
	else:
		print(total)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	d = s // c
	r = s % c
	print(d ** 2 * (c - r) + (d + 1) ** 2 * r)


def main():

	def solve():
		(c, sum) = map(int, input().split())
		pan = sum // c
		extra = sum % c
		result = (c - extra) * pan * pan + extra * (pan + 1) * (pan + 1)
		print(result)
	q = int(input())
	for _ in range(q):
		solve()

def __starting_point():
	main()
__starting_point()


def split(x, n):
	a = []
	if x < n:
		print(-1)
	elif x % n == 0:
		for i in range(n):
			a.append(x // n)
	else:
		zp = n - x % n
		pp = x // n
		for i in range(n):
			if i >= zp:
				a.append(pp + 1)
			else:
				a.append(pp)
	return a
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	if n >= x:
		print(x)
		continue
	a = split(x, n)
	s = 0
	for i in a:
		s += i * i
	print(s)


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	b = s // c
	k = s % c
	sum = k * (b + 1) ** 2
	sum += (c - k) * b ** 2
	print(sum)


n = int(input())
for i in range(n):
	answer = 0
	(c, s) = map(int, input().split())
	m = s // c
	answer += m ** 2 * (c - s % c)
	answer += (m + 1) ** 2 * (s % c)
	print(answer)


T = int(input())
anwer = ''
for t in range(T):
	text = input().split(' ')
	maximum = int(text[0])
	need = int(text[1])
	one = need // maximum
	if one == 0:
		anwer += str(need) + '\n'
		continue
	ost = need - maximum * one
	if ost == 0:
		n = need / one
		anwer += str(int(one ** 2 * n)) + '\n'
		continue
	boost = ost // maximum
	boost2 = ost - maximum * boost
	one += boost
	cost = 0
	k = maximum - boost2
	for i in range(maximum):
		if boost2:
			cost += (one + 1) ** 2
			boost2 -= 1
		else:
			cost += one ** 2 * k
			break
	anwer += str(int(cost)) + '\n'
print(anwer)


n = int(input())
for y in range(n):
	ent = list(map(int, input().split()))
	if ent[1] % ent[0] == 0:
		print(int((ent[1] / ent[0]) ** 2 * ent[0]))
	elif ent[0] >= ent[1]:
		print(ent[1])
	else:
		aux1 = ent[1] // ent[0]
		aux2 = ent[0] - ent[1] % ent[0]
		resp = aux1 ** 2 * aux2
		resp += (aux1 + 1) ** 2 * (ent[1] % ent[0])
		print(resp)


n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split(' ')]
	if a >= b:
		print(b)
	else:
		c = int(b / a)
		d = b % a
		print((a - d) * c ** 2 + d * (c + 1) ** 2)


import math
n = int(input())

def calculate(x, y):
	sum = 0
	bat_size = math.floor(y / x)
	count = y - bat_size * x
	if count == 0:
		count = x
	else:
		bat_size += 1
	sum += bat_size ** 2 * count
	y -= bat_size * count
	if y > 0:
		count = x - 1 - count
		bat_size -= 1
		sum += bat_size ** 2 * count
		y -= bat_size * count
		sum += y ** 2
	return int(sum)
result = []
for i in range(0, n):
	(x, y) = map(int, input().split())
	result.append(calculate(x, y))
for res in result:
	print(res)


from math import ceil
for i in range(int(input())):
	(c, s) = map(int, input().split())
	m = ceil(s / c)
	k = c * m - s
	print((c - k) * m ** 2 + k * (m - 1) ** 2)


from math import ceil, floor
n = int(input())
for i in range(n):
	(c, s) = input().split()
	c = int(c)
	s = int(s)
	ext = s % c
	s /= c
	c1 = ceil(s) ** 2 * ext
	c2 = floor(s) ** 2 * (c - ext)
	print(int(c1) + int(c2))


t = input()
for _ in range(0, int(t)):
	s = input()
	ss = s.split()
	c = int(ss[0])
	summ = int(ss[1])
	c1 = int(summ / c)
	c2 = summ - c1 * c
	c11 = (c1 + 1) * (c1 + 1)
	c10 = c1 * c1
	c21 = (c11 - c10) * c2
	newsum = c * c1 * c1
	print(c21 + newsum)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	p = b // a
	q = b % a
	s = (a - q) * p ** 2 + q * (p + 1) ** 2
	print(s)


import math
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	q = b // a
	r = b % a
	print(q ** 2 * (a - r) + r * (q + 1) ** 2)


from math import ceil
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = ceil(b / a)
	d = a * c - b
	print(c * c * (a - d) + (c - 1) * (c - 1) * d)


n = int(input())
for i in range(n):
	(cost, sm) = list(map(int, input().split()))
	ans = 0
	if sm % cost == 0:
		ans = cost * (sm // cost) ** 2
	else:
		floor = sm // cost
		rem = sm % cost
		ans = (cost - rem) * floor ** 2 + rem * (floor + 1) ** 2
	print(ans)


n = int(input())
for i in range(n):
	(c, s) = map(lambda x: int(x), input().split(' '))
	a = s // c
	b = s % c
	res = b * (a + 1) ** 2 + (c - b) * a ** 2
	print(res)


for _ in range(int(input())):
	(c, s) = list(map(int, input().split()))
	r = s % c
	q = s // c
	if c > s:
		print(s)
		continue
	if r == 0:
		print(c * q ** 2)
	else:
		ans = r * (q + 1) ** 2 + (c - r) * q ** 2
		print(ans)


n = int(input())
for _ in range(n):
	(r, sec) = map(int, input().split())
	if r == 1:
		print(sec ** 2)
	elif r >= sec:
		print(sec)
	else:
		if sec % r == 0:
			num = sec / r
			total = r * num ** 2
		else:
			num = sec // r
			rem = sec % r
			total = rem * (num + 1) ** 2 + (r - rem) * num ** 2
		print(int(total))


t = int(input())
for _ in range(t):
	ans = 0
	(c, summ) = map(int, input().split())
	init = summ // c
	mod = summ % c
	ans = mod * (init + 1) ** 2
	ans = ans + (c - mod) * init ** 2
	print(ans)


import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : map(int, input().split())

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}{}'.format(i, sep))
INF = float('inf')
MOD = int(1000000000.0 + 7)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	arr = [0] * x
	i = 0
	j = 0
	while j < y:
		arr[i] += 1
		i += 1
		i %= x
		j += 1
	ans = 0
	for i in arr:
		ans += i * i
	print(ans)


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	if c == 1:
		print(s * s)
	elif s == 1:
		print(1)
	elif s % c == 0:
		print(c * (s // c) ** 2)
	else:
		a = s // c
		b = s // c + 1
		bw = s % c
		aw = (c - bw) * a * a
		bw = bw * b * b
		print(aw + bw)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	r = s // c
	l = s % c
	ans = r * r * (c - l) + (r + 1) ** 2 * l
	print(ans)


n = int(input())
for _ in range(n):
	(c, s) = [int(s) for s in input().split()]
	(a, r) = (s // c, s % c)
	cost = r * (a + 1) * (a + 1) + (c - r) * a * a
	print(cost)


def main():
	t = int(input())
	for i in range(t):
		(c, k) = list(map(int, input().split(' ')))
		if k == 1:
			print(k)
		elif c == 1:
			print(k ** 2)
		elif c > k:
			print(k)
		else:
			x = int(k / c)
			li = [x for i in range(c)]
			y = k - c * x
			j = 0
			while y > 0:
				li[j] += 1
				y -= 1
				j += 1
			sum = 0
			for j in range(c):
				sum += li[j] ** 2
			print(sum)
main()


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
for i in range(int(input())):
	(c, s) = map(int, input().split())
	rng = s // c
	ans = 0
	while rng * c != s:
		ans += (rng + 1) ** 2
		s -= rng + 1
		c -= 1
	ans += c * rng ** 2
	print(ans)


import math
a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	d = c // b
	print(b * d * d + c % b * (2 * d + 1))


k = int(input())
for _ in range(k):
	(a, b) = map(int, input().split())
	res = b // a
	r = b % a
	print((a - r) * res ** 2 + r * (res + 1) ** 2)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	a = []
	for i in range(c):
		a.append((s // c) ** 2)
		s = s - s // c
		c -= 1
	print(sum(a))


from sys import stdin

def mincost(c, s):
	a = s // c
	b = s - c * a
	return b * (a + 1) ** 2 + (c - b) * a ** 2
with stdin as fin:
	q = int(fin.readline().rstrip())
	for i in range(q):
		[a, b] = [int(i) for i in fin.readline().rstrip().split()]
		print(mincost(a, b))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = [b // a] * a
	for i in range(b % a):
		l[i] += 1
	print(sum((i ** 2 for i in l)))


from math import pow, floor

def fnc(c, s):
	return (c - s % c) * pow(s // c, 2) + s % c * pow(s // c + 1, 2)
t = int(input())
for _ in range(t):
	(c, s) = (int(x) for x in input().split(' '))
	print(int(fnc(c, s)))


import sys
import collections
from collections import Counter
import itertools
import math
import timeit
input = sys.stdin.readline

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
for _ in range(t):
	(k, n) = mi()
	t = n // k
	r = n - t * k
	print(r * (t + 1) ** 2 + (k - r) * t ** 2)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(a, b) = sep()
	arr = [b // a] * a
	rem = b % a
	for i in range(rem):
		arr[i] += 1
	ans = 0
	for i in range(a):
		ans += arr[i] ** 2
	print(ans)
testcase(int(inp()))


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	val = s // c
	m = s % c
	print((val + 1) ** 2 * m + val ** 2 * (c - m))


n = int(input())
for i in range(n):
	(c, total) = map(int, input().split())
	x = total // c
	y = total % c
	ans = x ** 2 * (c - y) + (x + 1) ** 2 * y
	print(ans)


n = int(input())
while n > 0:
	(a, b) = map(int, input().split())
	c = b % a
	d = b // a
	ans = 0
	ans = c * (d + 1) ** 2 + (a - c) * d ** 2
	print(ans)
	n -= 1


import sys
import math
import itertools
import collections

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
n = ii()
for i in range(n):
	(c, summ) = mi()
	print(c * (summ // c) ** 2 + (2 * (summ // c) + 1) * (summ % c))


for i in range(int(input())):
	a = list(map(int, input().split()))
	print(a[1] % a[0] * pow(a[1] // a[0] + 1, 2) + (a[0] - a[1] % a[0]) * pow(a[1] // a[0], 2))


n = int(input())
for i in range(0, n):
	(a, b) = map(int, input().split())
	t = b // a
	r = b - t * a
	print(r * (t + 1) ** 2 + (a - r) * t ** 2)


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	t = s // c
	rest = s % c
	print(rest * (t + 1) * (t + 1) + (c - rest) * t ** 2)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b:
		print(b)
	elif b % a == 0:
		print(b * (b // a))
	else:
		p = b // a
		k = b % a
		q = a - k
		print(q * p ** 2 + k * (p + 1) ** 2)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	if n == 1:
		print(s ** 2)
	elif s == 1:
		print(1)
	else:
		k = s % n
		m = (s - k) // n
		w = k * (m + 1) ** 2 + (n - k) * m ** 2
		print(w)


import math
t = int(input())
for i in range(t):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	x = math.ceil(b / a)
	n = a * x - b
	print(n * (x - 1) * (x - 1) + (a - n) * x * x)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a >= b:
		print(b)
	else:
		x = b // a
		ans = [0] * a
		for i in range(a):
			ans[i] = b // a
		for i in range(b - b // a * a):
			ans[i] += 1
		s = 0
		for i in ans:
			s += i ** 2
		print(s)


from __future__ import division, print_function

def main():
	import sys
	data = iter(map(int, sys.stdin.buffer.read().decode('ascii').split()))
	n = next(data)
	res = [None] * n
	for i in range(n):
		ci = next(data)
		sumi = next(data)
		if ci >= sumi:
			res[i] = sumi
		else:
			(div, mod) = divmod(sumi, ci)
			res[i] = mod * (div + 1) ** 2 + (ci - mod) * div ** 2
	sys.stdout.buffer.write('\n'.join((str(x) for x in res)).encode('ascii'))
	return 0
main()


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	a = s // c
	b = s % c
	print(b * (a + 1) ** 2 + (c - b) * a ** 2)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 1 or b == 1:
		print(pow(b, 2))
	else:
		ans = [0] * a
		while b != 0:
			for i in range(a):
				if b == 0:
					break
				else:
					ans[i] += 1
					b -= 1
		count = 0
		for i in range(len(ans)):
			count += pow(ans[i], 2)
		print(count)


for _ in range(int(input())):
	(c, sum_) = [int(__) for __ in input().split()]
	if sum_ <= c:
		print(sum_)
	else:
		print(sum_ % c * (sum_ // c + 1) ** 2 + (c - sum_ % c) * (sum_ // c) ** 2)


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())

def solve():
	t = 1
	t = int(input())
	while t:
		t -= 1
		(a, b) = mapi()
		x = b // a
		y = b % a
		print(y * (x + 1) ** 2 + (a - y) * x ** 2)
solve()


n = int(input())
ar2 = []
ar = []
for i in range(n):
	ar.append(list(map(int, input().split())))
	ar2.append(0)

def raspr(arr, c, sum):
	stoim = 0
	ind = 0
	arr.clear()
	for i in range(c):
		arr.append(0)
	while sum > 0:
		for i in range(len(arr)):
			if sum > 0:
				arr[i] += 1
				sum -= 1
	for i in arr:
		stoim = stoim + i * i
	print(stoim)
for i in ar:
	raspr(ar2, i[0], i[1])


n = int(input())
for _ in range(n):
	(r, s) = [*map(int, input().split())]
	print((s // r) ** 2 * (r - s % r) + (s // r + 1) ** 2 * (s % r))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if y % x == 0:
		print((y // x) ** 2 * x)
	else:
		mx = y // x + 1
		col = y - x * (y // x)
		ost = y - mx * col
		print(col * mx ** 2 + ost * (y // x))


for nt in range(int(input())):
	(c, s) = map(int, input().split())
	a = s // c
	b = s % c
	print((c - b) * a ** 2 + b * (a + 1) ** 2)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(c, su) = map(int, input().split())
		x = divmod(su, c)
		print(x[0] * x[0] * (c - x[1]) + (x[0] + 1) ** 2 * x[1])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	cl = s // c
	r = s % c
	cst = cl * cl * (c - r) + (cl + 1) ** 2 * r
	print(cst)


n = int(input())
for el in range(n):
	(c, s) = map(int, input().split())
	min_st = s % c * (s // c + 1) ** 2 + (c - s % c) * (s // c) ** 2
	print(min_st)


n = int(input())
for cn in range(1, n + 1):
	(a, b) = map(int, input().split())
	c = int(b / a)
	d = b % a
	sum = (a - d) * c * c
	sum = sum + d * (c + 1) * (c + 1)
	print(sum)


n = int(input())
for i in range(0, n):
	(c, sum_i) = list(map(int, input().split()))
	d = sum_i // c
	if sum_i % c == 0:
		print(d ** 2 * c)
	else:
		a = sum_i - c * d
		print(a * (d + 1) ** 2 + d ** 2 * (c - a))


from collections import deque
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	i = b // a
	j = b % a
	total = j * (i + 1) ** 2 + (a - j) * i ** 2
	print(total)


import math
t = int(input())
a = []
for i in range(t):
	(n, s) = map(int, input().split())
	a.append([n, s])
for i in a:
	n = i[0]
	s = i[1]
	if n >= s:
		print(int(s))
	else:
		k = s * s / n
		if s % n == 0:
			print(int(k))
		else:
			c = int(s // n)
			d = c + 1
			w = (d * n - s) * math.pow(c, 2) + (s - c * n) * math.pow(d, 2)
			print(int(w))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	(c, d) = divmod(b, a)
	res = 0
	for j in range(d):
		res += (c + 1) ** 2
	for j in range(a - d):
		res += c ** 2
	print(res)


for _ in range(int(input())):
	(ci, si) = map(int, input().split())
	x = si // ci
	y = si % ci
	print(x ** 2 * (ci - y) + (x + 1) ** 2 * y)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().strip().split())
	if a == 1:
		print(b ** 2)
	elif b == 1 or b <= a:
		print(b)
	elif b % a == 0:
		c = math.ceil(b / a)
		d = math.floor(b / a)
		print((b // a) ** 2 * a)
	else:
		m = b / a
		c = math.ceil(b / a)
		d = math.floor(b / a)
		p = b % a
		q = a - b % a
		print(c ** 2 * p + d ** 2 * q)


n = int(input())
for i in range(n):
	(c, s) = input().split()
	(c, s) = (int(c), int(s))
	total = 0
	section = 0
	remainder = 0
	if s < c:
		total = s
	else:
		remainder = s % c
		section = int(s / c)
		total = (c - remainder) * section ** 2
		total += remainder * (section + 1) ** 2
	print(int(total))


x = int(input())
for i in range(0, x):
	a = str(input()).split(' ')
	if int(a[0]) == 1 or int(a[1]) == 1:
		print(int(a[1]) ** 2)
	else:
		z = int(a[1]) // int(a[0])
		y = int(a[1]) % int(a[0])
		aux = int(a[0]) - y
		print(y * (z + 1) ** 2 + aux * z ** 2)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	div = b // a
	mod = b % a
	pieces = [div] * a
	i = 0
	while mod != 0:
		pieces[i] += 1
		i += 1
		mod -= 1
	print(sum((k ** 2 for k in pieces)))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	(c, s) = map(int, sys.stdin.readline().split(' '))
	v = s // c
	rem = s % c
	t1 = c - rem
	t2 = rem
	ans = t2 * ((v + 1) * (v + 1))
	ans += t1 * v * v
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


n = int(input())
for i in range(n):
	(c, s) = map(int, input().strip().split())
	left = s % c
	v = s // c
	o = 0
	for i in range(left):
		o += (v + 1) ** 2
	for i in range(left, c):
		o += v ** 2
	print(o)


n = int(input())
for _ in range(n):
	(c, sums) = map(int, input().split())
	if c == 1:
		print(sums ** 2)
	else:
		temp = sums // c
		rem = sums % c
		print((temp + 1) ** 2 * rem + temp ** 2 * (c - rem))


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	if s < c:
		print(s)
	else:
		b = s // c
		m = s % c
		a = [b + 1] * m + [b] * (c - m)
		print(sum((v ** 2 for v in a)))


def answer():
	(c, s) = map(int, input().split(' '))
	r = s // c
	q = s % c
	ret = (r + 1) ** 2 * q + r ** 2 * (c - q)
	return ret
n = int(input())
for i in range(n):
	out = answer()
	print(out)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if b < a:
		print(b)
		continue
	else:
		ss = b // a
		tt = b % a
		tot = 0
		tot += a * ss ** 2
		tot += tt * (ss + ss + 1)
		print(tot)


n = int(input())
for i in range(n):
	(c, sumi) = map(int, input().split(' '))
	d = int(sumi / c)
	rem = sumi % c
	print(rem * (d + 1) * (d + 1) + (c - rem) * d * d)


n = int(input())
(c, sum) = ([], [])
for i in range(n):
	(ci, sumi) = map(int, input().split())
	k = sumi // ci
	m = sumi % ci
	print((k + 1) ** 2 * m + k ** 2 * (ci - m))


n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
for i in range(n):
	a = arr[i][0]
	b = arr[i][1]
	if b % a == 0 and a > 1:
		print(int(b / a) ** 2 * a)
	elif a > b or a == b:
		print(b)
	elif a < b:
		hasil_bagi = int(b / a)
		hasil_bagi1 = hasil_bagi ** 2
		sisa_bagi = a - b % a
		sisa_bagi2 = a - sisa_bagi
		hasil_bagi2 = (hasil_bagi + 1) ** 2
		print(hasil_bagi ** 2 * sisa_bagi + hasil_bagi2 * sisa_bagi2)


def N1():
	t = int(input())
	for _ in range(t):
		(c, sum) = map(int, input().split())
		if c == 1 or sum == 1:
			print(sum ** 2)
		else:
			d = int(sum / c)
			r = int(sum % c)
			print(r * (d + 1) ** 2 + (c - r) * d ** 2)
N1()


from math import ceil, floor
n = int(input())
for _ in range(n):
	(n, s) = map(int, input().split())
	ans = 0
	v1 = s // n
	c2 = s % n
	c1 = n - c2
	ans += v1 ** 2 * c1
	ans += (v1 + 1) ** 2 * c2
	print(ans)


def f():
	(c, s) = [int(s) for s in input().split()]
	avrg = s // c
	bigCount = s % c
	smallCount = c - bigCount
	total = avrg ** 2 * smallCount + (avrg + 1) ** 2 * bigCount
	print(total)
n = int(input())
for i in range(n):
	f()


n = int(input())

def cal(c, s):
	if s <= c:
		return s
	else:
		t = s % c
		a = s // c
		return a ** 2 * (c - t) + (a + 1) ** 2 * t
for i in range(n):
	c_s = list(map(int, input().strip().split(' ')))
	print(cal(c_s[0], c_s[1]))


n = int(input())
for _ in range(n):
	(c, x) = map(int, input().split())
	m1 = x // c
	p = x % c
	ans = (m1 + 1) ** 2 * p + m1 ** 2 * (c - p)
	print(ans)


n = int(input())
for i in range(n):
	(c_i, sum_i) = list(map(int, input().split()))
	if c_i >= sum_i:
		result = sum_i
	else:
		rem = sum_i % c_i
		div = (sum_i - rem) // c_i
		result = (c_i - rem) * div ** 2 + rem * (div + 1) ** 2
	print(result)


t = int(input())
while t > 0:
	(c, s) = map(int, input().split())
	(a, b) = (s // c, s % c)
	print(b * (a + 1) ** 2 + (c - b) * a * a)
	t -= 1


n = int(input())
for i in range(n):
	(c, s) = tuple(map(int, input().split()))
	standart = s // c
	ost = s % c
	print((standart + 1) ** 2 * ost + standart ** 2 * (c - ost))


n = int(input())
res = []
for i in range(n):
	res.append(input().split())
for i in range(n):
	x = int(res[i][1]) // int(res[i][0])
	y = int(res[i][1]) % int(res[i][0])
	print((int(res[i][0]) - y) * x ** 2 + y * (x + 1) ** 2)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
	else:
		b = s // c
		k = s - b * c
		print(k * (b + 1) * (b + 1) + (c - k) * b * b)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	if s < n:
		print(s)
	elif s % n == 0:
		res = s // n
		print(n * res ** 2)
	else:
		rem = s % n
		val = s // n
		res = 0
		j = n - rem
		res += rem * (val + 1) ** 2
		res += j * val ** 2
		print(res)


x = int(input())
for _ in range(x):
	(a, b) = map(int, input().split())
	lol = [0] * a
	i = 0
	while i < b:
		lol[i % a] += 1
		i += 1
	k = 0
	for i in lol:
		k += i * i
	print(k)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	k = y % x
	p = y // x
	print(x * pow(p, 2) if k == 0 else (x - k) * pow(p, 2) + k * pow(p + 1, 2))


for i in range(int(input())):
	(c, s) = map(int, input().split())
	p = 0
	(k, l) = (s // c, s % c)
	print((c - l) * k ** 2 + l * (k + 1) ** 2)


n = int(input())
for _ in range(n):
	l = list(map(int, input().split()))
	r = l[1] // l[0]
	d = l[1] % l[0]
	f = (r + 1) ** 2 * d + (l[0] - d) * r ** 2
	print(f)


n = int(input())
for i in range(n):
	x = 0
	(c, s) = [int(x) for x in input().split()]
	if c >= s:
		print(s)
	else:
		r = s % c
		x = s // c
		if r != 0:
			s1 = x ** 2 * (c - r)
			j = 1
			for j in range(r):
				s1 = s1 + (x + 1) ** 2
			print(s1)
		else:
			s1 = x ** 2 * c
			print(s1)


T = int(input())
for t in range(T):
	(x, y) = [int(x) for x in input().split()]
	k = y // x
	r = y % x
	print(r * (k + 1) ** 2 + (x - r) * k ** 2)


for i in range(int(input())):
	(c, s) = [int(j) for j in input().split()]
	if s <= c:
		print(s)
	else:
		a = s // c
		p = s % c
		print(int(pow(a, 2) * (c - p) + pow(a + 1, 2) * p))


from math import ceil
from math import floor
n = int(input())
for _ in range(n):
	(c, s) = [int(u) for u in input().split()]
	if c == 1:
		print(s ** 2)
		continue
	elif s == 1:
		print(s)
		continue
	arr = [s / c] * c
	for i in range(s - c * (s // c)):
		arr[i] = ceil(arr[i])
	for i in range(len(arr)):
		arr[i] = floor(arr[i])
	cost = 0
	for i in arr:
		cost += i ** 2
	print(cost)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 1:
		print(b ** 2)
	elif b < a:
		print(b)
	else:
		m = b // a
		n = b % a
		print(int((m + 1) ** 2 * n + (a - n) * m ** 2))


n = int(input())
for i in range(n):
	(q, w) = map(int, input().split())
	e = w % q
	res = 0
	for o in range(q):
		res += (w // q + (e > 0)) ** 2
		e -= 1
	print(res)


from collections import *
from functools import reduce
import sys
input = sys.stdin.readline

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())
for _ in range(val()):
	(a, b) = li()
	print((b // a) ** 2 * (a - b % a) + (b // a + 1) ** 2 * (b % a))


from math import ceil
n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	cost = 0
	if c >= s:
		print(s)
	else:
		t_big = s % c
		n_small = s // c
		t_small = ceil((s - (n_small + 1) * t_big) / n_small)
		cost += pow(n_small + 1, 2) * t_big + pow(n_small, 2) * t_small
		print(cost)


n = int(input())
for i in range(n):
	(c, semi) = map(int, input().split())
	average = semi // c
	leftbig = semi % c
	leftsmall = c - leftbig
	key = average * average * leftsmall + (average + 1) * (average + 1) * leftbig
	print(key)


t = int(input())
s = []
for kngjng in range(0, t):
	x = input()
	xx = x.split()
	a = int(xx[0])
	b = int(xx[1])
	j = b // a
	l = b % a
	g = l * (j + 1) ** 2 + (a - l) * j ** 2
	s.append(g)
for i in s:
	print(i)


t = int(input())
for _ in range(t):
	(c, s) = map(int, input().split())
	e = s // c
	ee = e + 1
	mm = s % c
	m = c - mm
	ans = m * e * e + mm * ee * ee
	print(int(ans))


n = int(input())
for x in range(n):
	(c, total) = [int(i) for i in input().split()]
	if total <= c:
		print(total)
	else:
		if total % c == 0:
			print((total // c) ** 2 * c)
		cnt = 0
		iterations = c - total % c
		cnt += (total // c) ** 2 * iterations
		total -= total // c * iterations
		c -= iterations
		if c == 0:
			continue
		if total % c == 0:
			print(cnt + (total // c) ** 2 * c)


for i in ' ' * int(input()):
	(c, sum) = map(int, input().split())
	k = sum // c
	r = sum % c
	print((k + 1) ** 2 * r + k ** 2 * (c - r))


import math
n = int(input())
l1 = []
l2 = []
for _ in range(n):
	(x, y) = map(int, input().split())
	l1.append(x)
	l2.append(y)
for i in range(n):
	if l2[i] == 1:
		print(1)
	elif l2[i] == 0:
		print(0)
	elif l1[i] == 1:
		print(l2[i] ** 2)
	else:
		x = math.ceil(l2[i] / l1[i])
		if l2[i] % l1[i] != 0:
			y = l2[i] // l1[i]
			t = l2[i] % l1[i]
			sum = t * x ** 2 + (l1[i] - t) * y ** 2
			print(sum)
		else:
			print(l1[i] * x ** 2)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
t = I()
for _ in range(t):
	(c, s) = LI()
	a = s // c
	m = s - c * (s // c)
	an = a ** 2 * (c - m) + m * (a + 1) ** 2
	print(an)


from copy import deepcopy
n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	nn = s // c
	kk = s - nn * c
	a = kk * (nn + 1) ** 2 + (c - kk) * nn ** 2
	print(a)


for i in range(int(input())):
	(c, sum) = map(int, input().split())
	print((sum // c) ** 2 * (c - sum % c) + (sum // c + 1) ** 2 * (sum % c))


T = int(input())
for _ in range(0, T):
	(c, s) = map(int, input().split())
	L = []
	for i in range(c):
		L.append(s // c)
	for i in range(s % c):
		L[i] += 1
	tot = 0
	for i in L:
		tot += i * i
	print(tot)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	avg = int(m / n)
	res = int(m % n)
	ans = res * (avg + 1) * (avg + 1) + (n - res) * avg * avg
	print(ans)


import math
n = int(input())
for i in range(n):
	(c, n) = map(int, input().split())
	k = math.ceil(n / c)
	discount = k * c - n
	cost = k ** 2 * c - discount * (2 * k - 1)
	print(cost)


n = int(input())
for i in range(n):
	sum1 = 0
	(c, s) = map(int, input().split())
	if c > s:
		sum1 += s
	else:
		t = s // c
		if s % c != 0:
			e = s % c
			sum1 += (c - e) * t ** 2
			sum1 += e * (t + 1) ** 2
		else:
			sum1 += t ** 2 * c
	print(sum1)


for i in int(input()) * [0]:
	(a, b) = map(int, input().split())
	if b > a:
		c = b // a
		d = b % a
		l = [c] * a
		i = 0
		while d != 0:
			l[i] += 1
			d -= 1
			i += 1
			if i > len(l) - 1:
				i = 0
		print(sum((i * i for i in l)))
	else:
		print(b)


n = int(input())
for _ in range(n):
	(c, sn) = map(int, input().split())
	m = sn // c
	b = sn % c
	ans = (m + 1) * (m + 1) * b + m * m * (c - b)
	print(ans)


n = int(input())
for v in range(n):
	x = [int(q) for q in input().split()]
	c = x[0]
	s = x[1]
	l = s // c
	m = s % c
	if m != 0:
		ans = (l + 1) ** 2 * m + (c - m) * l ** 2
	else:
		ans = l ** 2 * c
	print(ans)


from math import *
from sys import stdin

def arr_inp():
	return [int(x) for x in stdin.readline().split()]
for i in range(int(input())):
	(c, s) = arr_inp()
	(low, upp) = (floor(s / c), ceil(s / c))
	print(low ** 2 * (c - s % c) + upp ** 2 * (s % c))


n = int(input())
for room in range(n):
	A = [int(x) for x in input().split()]
	(c, sumi) = (A[0], A[1])
	if sumi <= c:
		print(sumi)
	else:
		total = sumi % c * (sumi // c + 1) ** 2 + (c - sumi % c) * (sumi // c) ** 2
		print(total)


n = int(input())
for i in range(n):
	(count, minSum) = list(map(int, input().split()))
	ost = minSum % count
	r = minSum // count
	ans = r ** 2 * count
	ans -= ost * r ** 2
	ans += (r + 1) ** 2 * ost
	print(ans)


from math import ceil
from math import factorial
import collections
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
t = ii()
for i in range(t):
	(x, y) = iia()
	if y == 1:
		print(y ** 2)
	elif x == 1:
		print(y ** 2)
	elif y > x:
		a = y // x
		b = y % x
		c = (a + 1) ** 2 * b + (x - b) * a ** 2
		print(c)
	else:
		print(y)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	if n >= m:
		print(m)
	else:
		(x, y) = (m // n, m % n)
		print((n - y) * x * x + y * (x + 1) * (x + 1))


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	(c, s) = nm()
	print(s % c * (s // c + 1) ** 2 + (c - s % c) * (s // c) ** 2)
	return
T = ni()
for _ in range(T):
	solve()


def run_testcase():
	n = int(input())
	for i in range(n):
		[maxr, sumr] = [int(x) for x in input().split()]
		if maxr >= sumr:
			print(sumr)
			continue
		div = sumr // maxr
		rem = sumr % maxr
		cost = (maxr - rem) * div ** 2 + rem * (div + 1) ** 2
		print(cost)
run_testcase()


n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	cnt = 0
	arr = 0
	while 1:
		if b - a < 0:
			for j in range(b):
				arr += (cnt + 1) ** 2
			for j in range(a - b):
				arr += cnt ** 2
			break
		else:
			cnt += 1
			b -= a
	print(arr)


n = int(input())
for _ in range(n):
	(c, su) = map(int, input().split())
	to = su % c * (su // c + 1) ** 2 + (c - su % c) * (su // c) ** 2
	print(to)


n = int(input())
for i in range(n):
	(c, s) = list(map(int, input().split()))
	t = s // c
	print((t + 1) * (s % c) * (t + 1) + t * t * (c - s % c))


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	(a, b) = value()
	res = b // a
	val = b % a
	ans = (res + 1) ** 2 * val + res ** 2 * (a - val)
	print(ans)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	k = s // c
	l = s - k * c
	print(k * k * (c - l) + (k + 1) ** 2 * l)


n = int(input())
for _ in range(n):
	(ci, sumi) = map(int, input().split())
	min_v = sumi // ci
	cnt2 = sumi - ci * min_v
	cnt1 = ci - cnt2
	print(min_v ** 2 * cnt1 + (min_v + 1) ** 2 * cnt2)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	(d, r) = divmod(s, c)
	print(r * (d + 1) ** 2 + (c - r) * d ** 2)


import sys
input = sys.stdin.readline
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
for (a, b) in AB:
	c = b // a
	p1 = b % a
	ans = (c + 1) ** 2 * p1 + c ** 2 * (a - p1)
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	if n == 1:
		print(m ** 2)
	elif m == 1:
		print(1)
	elif n < m:
		if m % n == 0:
			ans = (m // n) ** 2 * n
		else:
			a1 = m % n
			a2 = m // n
			ans = (a2 + 1) ** 2 * a1
			ans = ans + a2 ** 2 * (n - a1)
		print(ans)
	elif m == n:
		print(m)
	else:
		print(m)


import math
for _ in range(int(input())):
	(c, sum) = map(int, input().split())
	ans = 0
	if sum > c:
		ans += c * (sum // c) ** 2 - sum % c * (sum // c) ** 2 + sum % c * (sum // c + 1) ** 2
	elif sum == c:
		ans += c
	else:
		ans += sum
	print(ans)


for i in range(int(input())):
	(ci, sumi) = [int(s) for s in input().split()]
	print((sumi // ci) ** 2 * (ci - sumi % ci) + (sumi // ci + 1) ** 2 * (sumi % ci))


n = int(input())
for i in range(n):
	(c, s) = [int(i) for i in input().split()]
	x = s // c
	d = s % c
	su = x ** 2 * c + d * (x * 2 + 1)
	print(su)


for _ in range(int(input())):
	(c, s) = list(map(int, input().split()))
	x = s % c
	y = s // c
	ans = y ** 2 * (c - x) + x * (y + 1) ** 2
	print(ans)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	(n, m) = get_int_list()
	if n >= m:
		print(m)
	elif n == 1:
		print(m ** 2)
	elif m >= n:
		each_room = m // n
		residue = m % n
		if residue == 0:
			print(each_room ** 2 * n)
		else:
			print(each_room ** 2 * (n - residue) + (each_room + 1) ** 2 * residue)


n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
for (c, s) in a:
	minVal = s // c
	rem = s % c
	print(minVal ** 2 * (c - rem) + (minVal + 1) ** 2 * rem)


n = int(input())
for i in range(n):
	(c, sum) = [int(x) for x in input().split()]
	if c == 1:
		print(sum ** 2)
		continue
	print((sum // c) ** 2 * (c - sum % c) + (sum // c + 1) ** 2 * (sum % c))


x = int(input())
for i in range(x):
	(n, m) = [int(a) for a in input().split()]
	d = m // n
	f = m % n
	s = d ** 2 * (n - f) + (d + 1) ** 2 * f
	print(s)


tc = int(input())
for i in range(tc):
	(c, sum) = [int(x) for x in input().split()]
	arr = [sum // c for x in range(c)]
	print(sum % c * (arr[0] + 1) ** 2 + (c - sum % c) * arr[0] ** 2)


import sys
import bisect as b
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for i in range(inin()):
	(c, s) = cin()
	if c >= s:
		print(s)
	else:
		mod = s % c
		div = s // c
		print(mod * (div + 1) ** 2 + (c - mod) * div ** 2)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		(a, b) = num()
		x = [0] * a
		while b != 0:
			i = 0
			while i < a:
				x[i] += 1
				b -= 1
				i += 1
				if b == 0:
					break
		ss = 0
		for i in range(a):
			ss += x[i] * x[i]
		print(ss)
solve()


for i in range(int(input())):
	a = list(map(int, input().split()))
	k = []
	for j in range(a[0]):
		k.append(0)
	number_of_sec = a[1]
	max_no_rad = a[0]
	quotient = a[1] // a[0]
	remainder = a[1] % a[0]
	for l in range(len(k)):
		k[l] = quotient
	for pq in range(remainder):
		k[pq] = k[pq] + 1
	t = 0
	for hpn in range(len(k)):
		t = t + k[hpn] ** 2
	print(t)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(c, s) = map(int, sys.stdin.readline().split())
	a = s // c
	k = s % c
	ans = (c - k) * a ** 2 + k * (a + 1) ** 2
	print(ans)


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for (c, sumk) in a:
	k = sumk // c
	x = sumk - k * c
	print(k ** 2 * (c - x) + (k + 1) ** 2 * x)


import sys, math
input = sys.stdin.readline

def inp():
	n = int(input())
	return n

def inlt():
	a = list(map(int, input().split()))
	return a

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	(a, b) = map(int, input().split())
	return (a, b)
t = 1
t = inp()
for tt in range(t):
	(c, s) = invr()
	q = s // c
	w = s % c
	qw = c - w
	print(q * q * qw + (q + 1) ** 2 * w)


def split(x, n):
	ans = []
	zp = n - x % n
	pp = x // n
	for i in range(n):
		if i >= zp:
			ans.append(pp + 1)
		else:
			ans.append(pp)
	return ans
n = int(input())
for i in range(n):
	(c, Sum) = [int(ele) for ele in input().split()]
	pp = Sum // c
	zp = c - Sum % c
	S = (pp + 1) * (pp + 1) * (c - zp) + pp * pp * zp
	print(S)


from sys import stdin
input = stdin.readline
n = int(input())
for i in range(n):
	(c, m) = map(int, input().split())
	d = m // c
	t = m % c
	ans = d * d * (c - t) + (d + 1) * (d + 1) * t
	print(ans)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	x = s // c
	y = s % c
	ans = (c - y) * (x * x) + y * ((x + 1) * (x + 1))
	print(ans)


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
	else:
		(x, y) = divmod(s, c)
		ans = 0
		while c > 0:
			if y >= 1:
				ans += (x + 1) ** 2
				y -= 1
				c -= 1
			else:
				ans += x ** 2
				c -= 1
		print(ans)


from sys import stdin

def rl():
	return [int(w) for w in stdin.readline().split()]
test = int(stdin.readline())
while test:
	test -= 1
	(a, b) = rl()
	tmp = b // a
	t = b % a
	res = int
	res = 0
	for i in range(a - t):
		res = res + tmp * tmp
	for i in range(t):
		res = res + (tmp + 1) * (tmp + 1)
	print(res)


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	n = Read.int()
	for q in range(n):
		(c, s) = Read.list_int()
		t = math.ceil(s / c)
		g = t * c - s
		res = t * t * (c - g) + (t - 1) * (t - 1) * g
		print(res)
query_count = 1
while query_count:
	query_count -= 1
	solve()


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	if s <= c:
		print(s)
	else:
		a = s // c
		b = s % c
		s1 = b * (a + 1) * (a + 1) + (c - b) * a * a
		print(s1)


n = int(input())
for i in range(n):
	(c, s) = [int(x) for x in input().split()]
	t1 = s // c
	t2 = s - c * t1
	t3 = c - t2
	print(t2 * (t1 + 1) * (t1 + 1) + t3 * t1 * t1)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(c, sm) = MAP()
	a = sm // c
	b = sm % c
	ans = 0
	for i in range(b):
		ans += (a + 1) ** 2
	for i in range(b, c):
		ans += a ** 2
	print(ans)


for i in range(int(input())):
	(c, sum) = list(map(int, input().split()))
	if c >= sum:
		print(sum)
	else:
		a = sum // c
		b = sum % c
		p = 0
		for k in range(b):
			p += (a + 1) ** 2
		print(p + a ** 2 * (c - b))


for _ in range(int(input())):
	(b, a) = map(int, input().split())
	div = a // b
	mod = a % b
	print((b - mod) * div ** 2 + mod * (div + 1) ** 2)


n = int(input())
l = []
for i in range(n):
	l = input().split()
	ci = int(l[0])
	sumi = int(l[1])
	r = sumi % ci
	ans = (ci - r) * (sumi // ci) ** 2 + r * (sumi // ci + 1) ** 2
	print(ans)


t = int(input())
for nt in range(t):
	(c, s) = [int(k) for k in input().strip().split(' ')]
	res = 0
	nba = s // c
	nbap = nba + 1
	np = s % c
	na = c - np
	print(np * nbap * nbap + na * nba * nba)


import sys
input = sys.stdin.readline
N = int(input())
for _ in range(N):
	(c, s) = map(int, input().split())
	l = [0] * c
	t = s + 0
	for i in range(s):
		if t == 0:
			break
		l[i % c] += 1
		t -= 1
	res = 0
	for i in range(c):
		res += l[i] ** 2
	print(res)


n = int(input())
for i in range(n):
	(c, sessao) = list(map(int, input().split(' ')))
	if c == sessao:
		print(c)
	elif c > sessao:
		print(sessao)
	else:
		total = 0
		if sessao % c == 0:
			numRadiador = sessao / c
			for j in range(c):
				total = total + numRadiador * numRadiador
		else:
			numRadiador = int(sessao / c)
			numAux = sessao - numRadiador * c
			numRadiador2 = numRadiador + 1
			for j in range(numAux):
				total = total + numRadiador2 * numRadiador2
			for j in range(c - numAux):
				total = total + numRadiador * numRadiador
		print(int(total))


for n in range(int(input())):
	(c, sum) = list(map(int, input().split()))
	x = sum // c
	r = sum % c
	print(r * (x + 1) ** 2 + (c - r) * x ** 2)


for _ in range(int(input())):
	(X, Y) = map(int, input().split())
	n = Y // X
	y = Y % X
	if y == 0:
		print(n * n * X)
	else:
		z = Y % X
		z = X - z
		n = (Y + z) // X
		print(n * n * (X - z) + (n - 1) * (n - 1) * z)


import math
import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
	(q, p) = map(int, input().split())
	if q >= p:
		ans = p
	elif p % q == 0:
		ans = q * (p // q) * (p // q)
	else:
		m = p // q
		(a, b) = (q - p + m * q, p - m * q)
		ans = a * m * m + b * (m + 1) * (m + 1)
	print(ans)


n = int(input())
vse = []
kolvo = 0
for _ in range(n):
	(c, sumi) = input().split()
	c = int(c)
	sumi = int(sumi)
	if sumi % c == 0:
		if c == 1:
			vse += [sumi ** 2]
		elif sumi == c:
			vse += [1 * c]
		else:
			vse += [(sumi // c) ** 2 * c]
	elif sumi == 1:
		vse += [1]
	else:
		k = sumi // c
		l = sumi % c
		vse = vse + [k ** 2 * (c - l) + (k + 1) ** 2 * l]
for _ in range(n):
	print(vse[_])


import sys

def main():
	data = sys.stdin.read().split('\n')
	answers = []
	N = int(data[0])
	for row in data[1:N + 1]:
		(c, s) = map(int, row.split(' '))
		k1 = s // c
		c2 = s % c
		k2 = k1 + 1
		c1 = c - c2
		assert c1 + c2 == c
		assert k1 * c1 + k2 * c2 == s
		assert k2 == k1 + 1
		answers.append(str(c1 * k1 * k1 + c2 * k2 * k2))
	sys.stdout.write('\n'.join(answers) + '\n')
main()


t = int(input())
while t > 0:
	t -= 1
	(c, s) = map(int, input().split())
	if c == 1:
		print(s ** 2)
	elif s < c:
		print(s)
	elif s >= c:
		if s % c == 0:
			z = int(s / c)
			print(c * z ** 2)
		else:
			x = s % c
			y = int(s / c)
			sum = x * (y + 1) ** 2 + (c - x) * y ** 2
			print(sum)


def solve(c, total):
	(div, rem) = divmod(total, c)
	return rem * (div + 1) ** 2 + (c - rem) * div ** 2
for _ in range(int(input())):
	(c, total) = map(int, input().split())
	print(solve(c, total))


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
for _ in range(n):
	(c, _sum) = map(int, input().split())
	a = _sum // c
	b = _sum % c
	answer = a ** 2 * (c - b) + (a + 1) ** 2 * b
	print(answer)


def calc(t, c):
	if c < t:
		print(c)
	else:
		sum = 0
		for i in range(t):
			temp = c // (t - i)
			sum += temp ** 2
			c -= temp
		print(sum)
n = int(input())
for i in range(n):
	(t, c) = list(map(int, input().split()))
	calc(t, c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n >= k:
		print(k)
	else:
		var = k // n
		rem = k % n
		print(rem * (var + 1) ** 2 + (n - rem) * var ** 2)


for _ in range(int(input())):
	(a, b) = map(int, input().split(' '))
	if a >= b:
		print(b)
	else:
		reps = b // a
		rem = b % a
		foo = (a - rem) * reps ** 2
		bar = rem * (reps + 1) ** 2
		print(foo + bar)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	aa = [0] * a
	k = b // a
	rem = b % a
	for i in range(a):
		aa[i] = k ** 2
	for i in range(rem):
		aa[i] = (k + 1) ** 2
	print(sum(aa))


n = int(input())
for _ in range(n):
	(c, k) = map(int, input().strip().split())
	x = k // c
	y = k % c
	ans = y * (x + 1) ** 2 + (c - y) * x ** 2
	print(ans)


for _ in range(int(input())):
	(k, n) = [int(i) for i in input().split()]
	t = n // k
	r = n - t * k
	print(r * (t + 1) ** 2 + (k - r) * t ** 2)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a > b:
		print(b)
	else:
		num = b // a
		count2 = b % a
		count1 = a - count2
		ans = num ** 2 * count1 + (num + 1) ** 2 * count2
		print(ans)


def optimal(max_rad, min_sec, cost):
	base = min_sec // max_rad
	add = min_sec % max_rad
	return add * (base + 1) ** 2 + (max_rad - add) * base ** 2

def main():
	num_rooms = int(input())
	answ = []
	count = 1
	for i in range(num_rooms):
		(max_rad, min_sec) = list(map(int, input().split()))
		opt = optimal(max_rad, min_sec, count)
		answ.append(opt)
		count += 1
	for opt in answ:
		print(opt)
main()


import sys

def input():
	return sys.stdin.readline()

def mapi():
	return map(int, input().split())

def maps():
	return map(str, input().split())

def solve():
	t = 1
	t = int(input())
	while t:
		t -= 1
		(a, b) = mapi()
		x = b // a
		y = b % a
		print(y * (x + 1) ** 2 + (a - y) * x ** 2)
solve()


n = int(input())
for i in range(n):
	(sa, sb) = input().split()
	a = int(sa)
	b = int(sb)
	k = b // a
	ak = b % a
	res = int(k ** 2 * (a - ak) + (k + 1) ** 2 * ak)
	print(res)


n = int(input())
for i in range(n):
	x = list(map(int, input().split(' ')))
	print(x[1] % x[0] * (x[1] // x[0] + 1) ** 2 + (x[1] // x[0]) ** 2 * (x[0] - x[1] % x[0]))


a = int(input())
o = []
z = 0
for i in range(0, a):
	l = list(map(int, input().split()))
	n = l[0]
	m = l[1]
	p = l[1] % l[0]
	if n > m:
		print(m)
		continue
	if m == 1:
		print(1)
		continue
	for j in range(0, l[0]):
		o.append(1)
		o[j] = l[1] // l[0]
		while p != 0:
			o[j] += 1
			p = p - 1
			break
	for j in range(0, l[0]):
		o[j] = o[j] * o[j]
	print(sum(o))
	o.clear()
	l.clear()


n = int(input())
for i in range(n):
	(c, sm) = list(map(int, input().split()))
	x = sm // c
	ans = 0
	for j in range(c):
		ans += x * x
	for j in range(sm % c):
		ans -= x * x
		ans += (x + 1) * (x + 1)
	print(ans)


from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 6)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))

def main():
	n = iin()
	for _ in range(n):
		(c, s) = lin()
		(t1, t2) = (c, s % c)
		t1 -= t2
		cost = 0
		x = s // c
		left = min(s // x, t1) if x else 0
		cost += left * x ** 2
		s -= left * x
		x += 1
		left = min(s // x, t2)
		cost += left * x ** 2
		s -= left * t2
		print(cost)
main()


from sys import stdin

def solve():
	for _ in range(int(stdin.readline())):
		(c, sm) = map(int, stdin.readline().split())
		q = sm // c
		r = sm % c
		res = q ** 2 * (c - r) + (q + 1) ** 2 * r
		print(res)
solve()


for i in range(int(input())):
	(c, s) = [int(x) for x in input().split()]
	t = s % c
	k = s // c
	print((k + 1) ** 2 * t + k ** 2 * (c - t))


t = int(input())
for i in range(t):
	(c, s) = [int(i) for i in input().split()]
	if c >= s:
		print(s)
	elif c == 1:
		print(s ** 2)
	elif c < s:
		if s % c == 0:
			print((s // c) ** 2 * c)
		else:
			rem = s % c
			each = s // c
			res = (each + 1) ** 2 * rem
			final_rem = c - rem
			print(res + each ** 2 * final_rem)


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	sum = (a - b % a) * (b // a) ** 2
	sum += b % a * (b // a + 1) ** 2
	print(sum)


def main():
	n = int(input())
	for i in range(n):
		(c, s) = map(int, input().split())
		k = s % c
		p = s // c
		ans = (p + 1) ** 2 * k + p ** 2 * (c - k)
		print(ans)
	return
main()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	base = b // a
	mod = b % a
	sum = base ** 2 * (a - mod) + (base + 1) ** 2 * mod
	print(sum)


import math
t = int(input())
while t:
	n = 1
	while n:
		(c, s) = map(int, input().split())
		suma = 0
		k = s // c
		suma = k ** 2 * c
		m = s % c
		suma += m * (1 + 2 * k)
		print(suma)
		n -= 1
	t -= 1


import math
n = int(input())
for _ in range(n):
	(rads, secs) = map(int, input().split())
	k = secs // rads
	rem = secs % rads
	print(rem * (k + 1) ** 2 + k ** 2 * (rads - rem))


t = int(input())
while t > 0:
	(c, s) = [int(x) for x in input().split()]
	r = (c - s % c) * pow(s // c, 2)
	r += s % c * pow(s // c + 1, 2)
	print(r)
	t -= 1


t = int(input())
for i in range(0, t):
	a = [int(x) for x in input().split()]
	if a[0] >= a[1]:
		print(a[1])
	else:
		c = a[1] // a[0]
		r = a[1] % a[0]
		print((a[0] - r) * c ** 2 + r * (c + 1) ** 2)


n = int(input())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	if y % x == 0:
		print((y // x) ** 2 * x)
	else:
		k = y // x
		c = y % x
		print(y % x * (k + 1) ** 2 + (x - y % x) * k ** 2)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	k = s // c
	r = s % c
	soma = r * (k + 1) ** 2 + (c - r) * k ** 2
	print(soma)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	big = s % c
	small = c - big
	print(small * (s // c) * (s // c) + big * (s // c + 1) * (s // c + 1))


import math
n = int(input())
for i in range(n):
	(c, sum_) = [int(s) for s in input().split()]
	num = math.floor(sum_ / c)
	add = sum_ % c
	ans = 0
	for j in range(c - add):
		ans += num ** 2
	for k in range(add):
		ans += (num + 1) ** 2
	print(ans)


import math
n = int(input())
for i in range(0, n):
	entrada = input().split()
	c = int(entrada[0])
	s = int(entrada[1])
	if c == 1 or s == 1:
		print(int(s ** 2))
	else:
		aux1 = s // c
		aux2 = s % c
		aux3 = c - aux2
		print(aux2 * (aux1 + 1) ** 2 + aux3 * aux1 ** 2)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
		continue
	b = s % c
	a = s // c
	if not b:
		print(a ** 2 * c)
		continue
	print(b * (a + 1) ** 2 + a ** 2 * (c - b))


n1 = int(input())
for i1 in range(n1):
	(a, b) = map(int, input().split())
	w = b // a
	r = b % a
	print(w ** 2 * (a - r) + r * (w + 1) ** 2)


import sys, itertools
tc = int(sys.stdin.readline())
for _ in range(tc):
	(c, s) = map(int, sys.stdin.readline().split())
	if c == 1:
		print(s ** 2)
	elif s == 1:
		print(1)
	else:
		temp = [0] * c
		for i in range(c):
			temp[i] = s // c
		s -= c * (s // c)
		for i in range(s):
			temp[i] += 1
		ans = 0
		for i in temp:
			ans += i ** 2
		print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		print(b)
	else:
		su = 0
		if b % a == 0:
			print(a * pow(b // a, 2))
		else:
			t = a - b % a
			z = b // a
			su += pow(z + 1, 2) * (b % a) + pow(z, 2) * t
			print(su)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
n = rint()
for _ in range(n):
	(c, s) = rints()
	if c >= s:
		print(s)
		continue
	s1 = s // c
	s2 = s1 + 1
	print(s2 ** 2 * (s % c) + s1 ** 2 * (c - s % c))


for i in range(int(input())):
	(c, tot) = map(int, input().split())
	arr = [0] * c
	base = tot // c
	sisa = tot - base * c
	ans = sisa * (base + 1) ** 2 + base * base * (c - sisa)
	print(ans)


n = int(input())
for nt in range(n):
	(a, b) = map(int, input().split())
	if b // a == 0:
		print(b)
	else:
		x = b // a
		y = b % a
		print(x ** 2 * (a - y) + (x + 1) ** 2 * y)


T = int(input())
a = [0, 0]
for ID in range(T):
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	r = b % a
	d = b // a
	res = r * (d + 1) * (d + 1) + (a - r) * d * d
	print(res)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	f = b // a
	ex = b % a
	s = (a - ex) * (b // a) ** 2
	s += ex * math.ceil(b / a) ** 2
	print(s)


T = int(input())
while T > 0:
	l = list(map(int, input().split(' ')))
	a = l[0]
	b = l[1]
	if a > b:
		print(int(b))
	elif b / a % 1 == 0:
		print(int(a * (b / a) ** 2))
	else:
		c = b // a
		b = b - c * a
		print(b * (c + 1) ** 2 + (a - b) * c ** 2)
	T -= 1


import math
for _ in range(int(input())):
	(nr, r) = map(int, input().split())
	mod = r % nr
	ans = math.ceil(r / nr) ** 2 * mod + (r // nr) ** 2 * (nr - mod)
	print(ans)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	w = b // a
	r = b % a
	print(w ** 2 * (a - r) + r * (w + 1) ** 2)


for i in range(int(input())):
	X = list(map(int, input().split()))
	Each = X[1] // X[0]
	print((Each + 1) ** 2 * (X[1] % X[0]) + Each ** 2 * (X[0] - X[1] % X[0]))


import math
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	if x == 1:
		print(y * y)
	else:
		k = math.ceil(y / x)
		p = k * x
		t = k * x - y
		ans = (x - t) * (k * k) + t * ((k - 1) * (k - 1))
		print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a >= b:
		print(b)
	else:
		x = b % a * (b // a + 1) ** 2 + (a - b % a) * (b // a) ** 2
		print(x)


n = int(input())
S = []
for _ in range(n):
	temp = list(map(int, input().split()))
	S.append(temp)
for i in range(n):
	t = S[i]
	a = t[1] // t[0]
	b = t[1] % t[0]
	print(b * (a + 1) ** 2 + (t[0] - b) * a ** 2)


from math import ceil
for i in range(int(input())):
	(c, s) = map(int, input().split())
	(t, d) = (s // c, s % c)
	print(d * (t + 1) ** 2 + (c - d) * t ** 2)


import math
for _ in range(int(input())):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
	else:
		y = s // c
		ans = (s - y * c) * (y + 1) ** 2 + (c - s + y * c) * y ** 2
		print(ans)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a > b:
		print(b)
		continue
	c = b // a
	d = b - a * c
	ans = (c + 1) ** 2 * d + c ** 2 * (a - d)
	print(ans)


n = int(input())
for _ in range(n):
	(c, su) = list(map(int, input().split()))
	tmp = su // c
	tmpm = su % c
	val = tmpm * [tmp + 1] + [tmp] * (c - tmpm)
	print(sum((i * i for i in val)))


import math
n = int(input())
for i in range(n):
	(m, k) = input().split()
	k = int(k)
	m = int(m)
	j = k // m
	t = k % m
	t = (m - t) * pow(j, 2) + t * pow(j + 1, 2)
	print(t)


from collections import Counter, deque, defaultdict, OrderedDict, namedtuple
from bisect import bisect_left, bisect_right, insort
from math import sqrt, ceil, floor, factorial, gcd
mod = 10 ** 9 + 7
from sys import stdin
t = int(stdin.readline())
while t:
	(c, s) = map(int, stdin.readline().split())
	if c == 1:
		k = pow(s, 2)
	elif s == 1:
		k = 1
	elif c == 2:
		k = (s // 2) ** 2
		k += pow(s - s // 2, 2)
	elif s <= c:
		k = s
	elif s % c == 0:
		k = (s // c) ** 2 * c
	else:
		l = [s // c] * c
		m = s % c
		i = 0
		while m > 0:
			l[i] += 1
			m -= 1
			i += 1
		k = 0
		for e in l:
			k += pow(e, 2)
	print(k)
	t -= 1


t = int(input())
for z in range(t):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
		continue
	a = s // c
	b = s % c
	ans = (c - b) * a ** 2 + b * (a + 1) ** 2
	print(ans)


t = int(input())
for _ in range(t):
	l1 = [int(x) for x in input().split()]
	c = l1[0]
	sumi = l1[1]
	unit = int(sumi / c)
	left = sumi % c
	if left == 0:
		print(c * unit ** 2)
	else:
		print(left * (unit + 1) ** 2 + (c - left) * unit ** 2)


n = int(input())
for i in range(n):
	(c, x) = map(int, input().split())
	ans1 = x // c
	ans2 = x % c
	ans3 = c - ans2
	print(ans1 ** 2 * ans3 + (ans1 + 1) ** 2 * ans2)


n = int(input())
import math
for i in range(n):
	(r, s) = map(int, input().split())
	minr = s // r
	maxr = math.ceil(s / r)
	no = s % r
	c = maxr ** 2 * no + minr ** 2 * (r - no)
	print(c)


from sys import stdin as s
for i in range(int(s.readline())):
	(a, b) = map(int, input().split())
	if a >= b:
		print(b)
	else:
		(x, y) = divmod(b, a)
		print(x ** 2 * (a - y) + (x + 1) ** 2 * y)


for i in range(0, int(input())):
	(c, s) = map(int, input().split())
	sph = s // c
	oh = s - sph * c
	s = 0
	if oh > 0:
		for j in range(0, oh):
			s += (sph + 1) ** 2
	for j in range(0, c - oh):
		s += sph ** 2
	print(s)


import sys
import math
from math import *
import builtins
import collections
input = sys.stdin.readline

def print(x, end='\n'):
	sys.stdout.write(str(x) + end)

def get_int():
	return int(input())

def get_list_ints():
	return list(map(int, input().split()))

def get_char_list():
	s = input()
	return list(s[:len(s) - 1])

def get_tuple_ints():
	return tuple(map(int, input().split()))

def print_iterable(p):
	print(' '.join(map(str, p)))

def CountFrequency(arr):
	return collections.Counter(arr)

def reverse(s):
	l = len(s)
	for i in range(l // 2):
		(s[i], s[l - i - 1]) = (s[l - i - 1], s[i])
	return s

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return high

def pow(a, n):
	if n == 0:
		return 1
	elif n % 2 == 0:
		return pow(a, n // 2) % const * (pow(a, n // 2) % const) % const
	else:
		return pow(a, n // 2) % const * (pow(a, n // 2) % const) * (a % const) % const

def main():
	t = get_int()
	for i in range(t):
		[c, sumi] = get_list_ints()
		if sumi % c == 0:
			b = sumi // c
			print(c * b * b)
		else:
			b = sumi / c
			b1 = math.floor(b)
			b2 = math.ceil(b)
			count1 = c - sumi % c
			count2 = sumi % c
			print(count1 * (b1 * b1) + count2 * (b2 * b2))
	pass
main()


def CostOfHeating(c, sum):
	t = sum // c
	cost = sum % c * (t + 1) ** 2 + (c - sum % c) * t ** 2
	return cost

def main():
	outl = []
	for i in range(int(input())):
		inl = input().split()
		outl.append(CostOfHeating(int(inl[0]), int(inl[1])))
	for i in outl:
		print(i)
main()


t = int(input())
for _ in range(t):
	(c, s) = map(int, input().split())
	dp = [0] * c
	x = s // c
	r = s % c
	print(r * (x + 1) ** 2 + (len(dp) - r) * x ** 2)


n = int(input())
for i in range(n):
	result = 0
	(ci, sumi) = map(int, input().split())
	reminder = sumi % ci
	result = reminder * (int(sumi / ci) + 1) ** 2 + (ci - reminder) * int(sumi / ci) ** 2
	print(result)


n = input()
n = int(n)
for _ in range(n):
	(a, b) = map(int, input().split())
	if a > b:
		ans = b
	else:
		average = b // a
		b -= average * a
		ans = b * (average + 1) ** 2 + (a - b) * average ** 2
	print(ans)


for i in range(int(input())):
	(c, sum_) = map(int, input().split())
	a = [1] * c
	sum__ = c
	i = 0
	if sum_ < c:
		print(sum_)
		continue
	rem = sum_ % c
	x = sum_ // c + 1
	ans = 0
	ans += x ** 2 * rem
	if rem != 0:
		sum_ -= x * rem
		c -= rem
		x = sum_ // c
		ans += x ** 2 * c
	else:
		x = sum_ // c
		ans += x ** 2 * c
	print(ans)


for _ in range(int(input())):
	(c, sm) = list(map(int, input().split()))
	o = sm % c
	snr = sm // c
	print(snr * snr * (c - o) + (snr + 1) * (snr + 1) * o)


n = int(input())
for _ in range(n):
	(ci, sumi) = list(map(int, input().split()))
	c = sumi // ci
	sumi -= c * ci
	count = (c + 1) ** 2 * sumi
	d = c ** 2 * (ci - sumi)
	print(count + d)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	if c == 1:
		print(s * s)
	else:
		num = s // c
		ost = s - num * c
		print((c - ost) * num * num + ost * (num + 1) * (num + 1))


n = int(input())
for _ in range(n):
	(c, m) = map(int, input().split())
	(nc, yc) = divmod(m, c)
	print((nc + 1) * (nc + 1) * yc + nc * nc * (c - yc))


import math
n = int(input())
for i in range(n):
	(c, sum) = map(int, input().split())
	pow = math.floor(sum / c)
	to_add = sum - pow * c
	cost = to_add * (pow + 1) ** 2 + (c - to_add) * pow ** 2
	print(cost)


from math import sqrt
a = int(input())
for i in range(a):
	(c, b) = map(int, input().split())
	k = b // c
	m = b % c
	if c < b:
		print(int(k ** 2 * (c - m) + (k + 1) ** 2 * m))
	else:
		print(b)


from math import ceil
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	yy = b // a
	tmp = yy + 1
	qq = b % a
	yy **= 2
	res = yy * (a - qq)
	tmp **= 2
	res += tmp * qq
	print(res)


n = int(input())
for i in range(n):
	ch = input()
	L = [int(i) for i in ch.split()]
	c = L[0]
	summ = L[1]
	nb = (summ // c + 1) ** 2 * (summ % c) + (summ // c) ** 2 * (c - summ % c)
	print(nb)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		print(b)
	elif b % a == 0:
		c = b // a
		print(a * c ** 2)
	else:
		d = b // a
		f = b % a
		h = a - f
		g = f * (d + 1) ** 2 + h * d ** 2
		print(g)


n = int(input())
for _ in range(n):
	(max_radiators, sections) = [int(i) for i in input().split()]
	variant = [sections // max_radiators] * max_radiators
	sections_left = sections - sum(variant)
	for i in range(sections_left):
		variant[i] += 1
	costs = [i * i for i in variant]
	print(sum(costs))


import sys
input = iter(sys.stdin.read().splitlines()).__next__
TC = int(input())
for tc in range(TC):
	(C, S) = map(int, input().split())
	parts = S // C
	rem = S % C
	res = (parts + 1) ** 2 * rem + parts ** 2 * (C - rem)
	print(res)


from math import ceil
n = int(input())
(c, sm) = ([], [])
for i in range(n):
	(v1, v2) = [int(x) for x in input().split()]
	c.append(v1)
	sm.append(v2)
ans = []
for i in range(n):
	v1 = sm[i] // c[i]
	v2 = v1 + 1
	rem = sm[i] % c[i]
	val = v1 * v1 * (c[i] - rem)
	val += v2 * v2 * rem
	ans.append(val)
for i in range(n):
	print(ans[i])


import math
n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	nk = s // c
	print((s - nk * c) * (nk + 1) ** 2 + (c - (s - nk * c)) * nk ** 2)


n = int(input())
for kase in range(n):
	(c, sum) = [int(x) for x in input().split()]
	x = sum // c
	y = sum % c
	ans = (x + 1) * (x + 1) * y + x * x * (c - y)
	print(ans)


n = int(input())
while n > 0:
	(a, b) = map(int, input().split())
	l = b // a
	r = b % a
	t = a - r
	ans = t * l ** 2 + r * (l + 1) ** 2
	print(ans)
	n = n - 1


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	if x <= n:
		print(x)
	else:
		mod = x % n
		print((x // n + 1) ** 2 * mod + (n - mod) * (x // n) ** 2)


import sys
n = int(sys.stdin.readline())
for i in range(n):
	(c, s) = [int(x) for x in sys.stdin.readline().split()]
	k = s // c
	m = s - k * c
	q = 0
	q += (k + 1) ** 2 * m + k ** 2 * (c - m)
	print(q)


q = int(input())
for i in range(q):
	(w, e) = map(int, input().split())
	r = e // w
	t = 0
	for i in range(e % w):
		t += (r + 1) ** 2
	for i in range(w - e % w):
		t += r ** 2
	print(t)


from collections import deque
from math import ceil, sqrt

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
t = ii()
while t:
	t -= 1
	(x, y) = mi()
	n1 = y // x
	n2 = y % x
	s = (n1 + 1) ** 2 * n2
	s += n1 * (y - n2 * (n1 + 1))
	print(s)


for i in range(int(input())):
	l = []
	(n, m) = map(int, input().split())
	if n > m:
		print(m)
	else:
		r = m % n
		h = m // n
		if r == 0:
			print(h * h * n)
		else:
			print((h + 1) * (h + 1) * r + h * h * (n - r))


import sys
rdl = sys.stdin.readline
N = int(rdl().strip())
for _ in range(N):
	(c, s) = map(int, rdl().strip().split())
	cost = (s // c + 1) ** 2 * (s % c) + (s // c) ** 2 * (c - s % c)
	print(cost)


import math
n = int(input())
ans = []
for i in range(n):
	(c, s) = map(int, input().split())
	if s % c == 0:
		mid = s // c
		ans.append(c * mid ** 2)
	else:
		low = s // c
		high = math.ceil(s / c)
		ans.append(high ** 2 * (s % c) + low ** 2 * (c - s % c))
print('\n'.join((str(x) for x in ans)))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	x = b // a
	y = b % a
	ans = (x + 1) ** 2 * y + x ** 2 * (a - y)
	print(ans)


n = int(input())
for i in range(n):
	o = 0
	s = input().split(' ')
	c = int(s[0])
	sum = int(s[1])
	q = sum // c
	a = [q] * c
	q1 = sum % c
	for j in range(q1):
		a[j] += 1
	for j in range(c):
		o += a[j] ** 2
	print(o)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
for y in range(n):
	(x, y) = map(int, input().split())
	if x >= y:
		print(y)
		continue
	else:
		s = y // x
		t = y % x
		ans = (s + 1) ** 2 * t
		if t != 0:
			ans += s ** 2 * ((y - t * (s + 1)) // s)
		else:
			ans += s ** 2 * x
		print(ans)


t = int(input())
for _ in range(t):
	(u, v) = map(int, input().split())
	rv = v // u
	r = u
	lv = rv + 1
	l = v - rv * r
	r = u - l
	print(lv ** 2 * l + rv ** 2 * r)


for i in range(0, int(input())):
	(a, b) = map(int, input().split())
	print((a - b % a) * (b // a) ** 2 + b % a * (b // a + 1) ** 2)


def ans(a, b):
	if a == 1:
		return b * b
	if a >= b:
		return b
	else:
		some = b // a
		x = b % a
		return x * (some + 1) ** 2 + (a - x) * some ** 2
tc = int(input())
for _ in range(tc):
	(a, b) = map(int, input().split())
	print(ans(a, b))


for u in range(int(input())):
	(x, y) = map(int, input().split())
	(m, k) = (y // x, y % x)
	print((x - k) * m ** 2 + k * (m + 1) ** 2)


n = int(input())
for i in range(n):
	(ci, sumi) = map(int, input().split())
	if sumi <= ci:
		print(sumi)
	elif sumi == 1:
		print(1)
	elif sumi % ci == 0:
		part = (sumi / ci) ** 2
		print(int(ci * part))
	else:
		val = sumi // ci
		curr = sumi
		part_x_plus = sumi - val * ci
		part_x = ci - part_x_plus
		res = part_x * val ** 2 + part_x_plus * (val + 1) ** 2
		print(int(res))


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	n = int(input())
	for _ in range(n):
		(c, s) = map(int, input().split())
		t = s // c
		a = s % c
		print((c - a) * t * t + a * (t + 1) * (t + 1))
main()


def solve(n, m):
	A = [m // n] * n
	for i in range(m % n):
		A[i] += 1
	ans = sum([a ** 2 for a in A])
	return ans

def main():
	cas = int(input())
	while cas > 0:
		cas -= 1
		(a, b) = map(int, input().split())
		ans = solve(a, b)
		print(ans)
main()


for i in range(int(input())):
	(r, s) = map(int, input().split())
	m = s // r
	if m > 0:
		n = s % r
		a = m * m * (r - n)
		m += 1
		a += m * m * n
		print(a)
	else:
		print(s)


n = int(input())
for i in range(n):
	p = [int(i) for i in input().split()]
	c = p[0]
	s = p[1]
	k = s // c
	os = s % c
	print(os * (k + 1) ** 2 + (c - os) * k ** 2)


import sys
n = int(sys.stdin.readline().rstrip())
for _ in range(n):
	(a, b) = map(int, sys.stdin.readline().rstrip().split())
	div = b // a
	diff = b % a
	res = 0
	for i in range(diff):
		res += (div + 1) * (div + 1)
	for i in range(a - diff):
		res += div * div
	print(res)


n = int(input())
for _ in range(n):
	(c, sumi) = [int(i) for i in input().split()]
	dec = sumi // c
	rem = sumi % c
	ans = (c - rem) * dec ** 2
	ans += rem * (dec + 1) ** 2
	print(ans)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	sisa = s % c
	part = s // c
	print(part ** 2 * (c - sisa) + (part + 1) ** 2 * sisa)


n = int(input())

def getAns(arr):
	c = arr[0]
	s = arr[1]
	if s > c:
		baseCost = s // c
		highCost = baseCost + 1
		total = (s - baseCost * c) * highCost ** 2
		total += (c - s % c) * baseCost ** 2
		print(str(total))
	else:
		print(s)
for i in range(n):
	getAns([int(x) for x in input().split(' ')])


a = int(input())
for x in range(a):
	(b, c) = map(int, input().split())
	if b == c or c < b:
		print(min(b, c))
	else:
		bb1 = c // b
		bb2 = bb1 + 1
		if c % b == 0:
			print(bb1 ** 2 * b)
		else:
			i_bb2 = c - b * (c // b)
			i_bb1 = b - i_bb2
			print(bb1 ** 2 * i_bb1 + bb2 ** 2 * i_bb2)


n = int(input())
for i in range(n):
	[c, s] = list(map(int, input().split()))
	r = s % c
	if r == 0:
		print(c * (s // c) ** 2)
	else:
		print(r * (s // c + 1) ** 2 + (c - r) * (s // c) ** 2)


n = int(input())
out = []
for i in range(n):
	csum = [int(c) for c in input().split()]
	if csum[0] >= csum[1]:
		out.append(csum[1])
	else:
		check = csum[1] % csum[0]
		ktr = csum[1] // csum[0]
		out.append(ktr * ktr * (csum[0] - check) + check * (ktr + 1) ** 2)
for i in range(n):
	print(out[i])


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
	else:
		ans = 0
		cost = s // c
		part1 = s % c
		part2 = c - part1
		ans += part2 * cost ** 2 + part1 * (cost + 1) ** 2
		print(ans)


t = int(input().strip())
sumi = 0
ci = 0
for case in range(t):
	(ci, sumi) = map(int, input().strip().split())
	q = sumi // ci
	r = sumi % ci
	print(r * (q + 1) ** 2 + (ci - r) * q ** 2)


def main():
	for i in range(int(input())):
		ans = 0
		(c, k) = map(int, input().split())
		if c >= k:
			ans += k
		else:
			(d, r) = (k // c, k % c)
			ans += (c - r) * d ** 2 + r * (d + 1) * (d + 1)
		print(ans)
main()


t = int(input())
for k in range(t):
	(a, b) = map(int, input().split())
	ans = 0
	if a > b:
		ans = b
	else:
		d = b // a
		ans += (d + 1) ** 2 * (b % a)
		ans += d ** 2 * (a - b % a)
	print(ans)


from math import floor
for _ in range(int(input())):
	(c, s) = map(int, input().split())
	a = floor(s / c)
	b = s - a * c
	print(b * (a + 1) ** 2 + (c - b) * a ** 2)


import sys
raw_data = sys.stdin.readlines()
testcases = raw_data.pop(0)
for case in raw_data:
	current_case = case.split()
	radiators = int(current_case[0])
	t_sections = int(current_case[1])
	if t_sections % radiators == 0:
		big_radiator = t_sections / radiators
	else:
		big_radiator = t_sections // radiators + 1
	small_radiator = big_radiator - 1
	num_of_big = t_sections - small_radiator * radiators
	if small_radiator != 0:
		num_of_small = (t_sections - big_radiator * num_of_big) / small_radiator
	else:
		num_of_small = 0
	cost = big_radiator ** 2 * num_of_big + small_radiator ** 2 * num_of_small
	print(int(cost))


for iii in range(int(input())):
	(c, summ) = map(int, input().split())
	q = summ // c
	r = summ % c
	print(r * (q + 1) ** 2 + (c - r) * q ** 2)


def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	for _ in range(N):
		(c, s) = map(int, input().split())
		d = s // c
		m = s % c
		print((d + 1) ** 2 * m + d ** 2 * (c - m))
main()


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	if s < c:
		print(s)
	else:
		div = s // c
		mod = s % c
		ans = pow(div + 1, 2) * mod
		ans += pow(div, 2) * (c - mod)
		print(ans)


num = int(input())
co = []
for i in range(num):
	co.append([int(i) for i in input().split()])
for i in range(num):
	x = co[i][1] // co[i][0]
	y = co[i][1] % co[i][0]
	total = (co[i][0] - y) * x ** 2 + y * (x + 1) ** 2
	print(total)


MOD = 10 ** 9 + 7
INT_MAX = 10 ** 20 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]

def power(a, x):
	res = 1
	while x > 0:
		if x & 1:
			res = res * a % MOD
		a = a * a % MOD
		x //= 2
	return res % MOD

def NCR_MOD(n, r):
	num = 1
	for i in range(n, n - r, -1):
		num = num * i % MOD
	for j in range(1, r + 1):
		num = num * power(j, MOD - 2) % MOD
	return num

def period(s):
	for p in range(1, len(s) + 1):
		bool = True
		if len(s) % p == 0:
			for i in range(len(s) - p):
				if s[i] != s[i + p]:
					bool = False
			if bool:
				return p

def calc(c, sum):
	k = sum // c
	rem = sum % c
	return (k + 1) ** 2 * rem + k ** 2 * (c - rem)
for _ in range(int(input())):
	(c, sum) = INPUT()
	print(calc(c, sum))


n = int(input())
a = []
for i in range(n):
	a.append([int(x) for x in input().split(' ')])
for i in a:
	c = i[0]
	sm = i[1]
	tot = 0
	div = sm // c
	sm -= div * c
	for p in range(c):
		if p + 1 <= sm:
			tot += (div + 1) ** 2
		else:
			tot += div ** 2
	print(tot)


for _ in range(int(input())):
	cs = list(str(input()).split(' '))
	c = int(cs[0])
	s = int(cs[1])
	all = s // c
	some = s % c
	result = some * (all + 1) ** 2 + (c - some) * all ** 2
	print(result)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
N = int(input())
for _ in range(N):
	(a, b) = map(int, input().split())
	div = b // a
	r = b % a
	ans = (div + 1) ** 2 * r + div ** 2 * (a - r)
	print(ans)


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	m = int(b / a)
	k = b % a
	print((a - k) * m * m + k * (m + 1) * (m + 1))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	x = b // a
	y = b % a
	z = x - y
	s = 0
	s += (a - y) * (x * x)
	s += y * (x + 1) * (x + 1)
	print(s)


t = int(input())
while t:
	t -= 1
	(n, m) = tuple(map(int, input().split()))
	if n >= m:
		print(m)
		continue
	div = m // n
	ans = (n - m % n) * (div * div) + m % n * (div + 1) * (div + 1)
	print(ans)


from math import floor
for _ in range(int(input())):
	(c, maxi) = map(int, input().split())
	minm = int(floor(maxi / c))
	rmdr = int(maxi % c)
	ans = minm ** 2 * (c - rmdr) + (minm + 1) ** 2 * rmdr
	print(ans)


T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	val = M // N
	rem = M % N
	print(rem * (val + 1) * (val + 1) + (N - rem) * val * val)


from math import pow
for room in range(int(input())):
	(c, k) = map(int, input().split())
	if c <= k:
		(a, b) = (k // c, k % c)
		print(int(pow(a + 1, 2) * b + pow(a, 2) * (c - b)))
	else:
		print(k)


n = int(input())
for room in range(n):
	(c, minsum) = [int(x) for x in input().split(' ')]
	if c >= minsum:
		print(minsum)
	else:
		l = [1] * c
		for i in range(minsum - c):
			l[i % len(l)] += 1
		res = 0
		for i in l:
			res += i * i
		print(res)


t = int(input())
for case_num in range(t):
	(a, b) = map(int, input().split(' '))
	num = b // a
	hi = b % a
	lo = 0 if num == 0 else (b - hi * (num + 1)) // num
	print(lo * num * num + hi * (num + 1) * (num + 1))


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
	else:
		val1 = s // c
		val2 = s % c
		print((c - val2) * val1 ** 2 + val2 * (val1 + 1) ** 2)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x >= y:
		print(y)
	else:
		k = y // x
		p = y % x
		ans = (x - p) * k * k + p * (k + 1) * (k + 1)
		print(ans)


for _ in range(int(input())):
	(c, s) = list((int(i) for i in input().split()))
	x = s % c
	print(x * (s // c + 1) ** 2 + (c - x) * (s // c) ** 2)


n = int(input())
cost = 0
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if a >= b:
		print(b)
	else:
		sp = b // a
		r = b % a
		print((sp + 1) ** 2 * r + sp ** 2 * (a - r))


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	k = s / c
	if k.is_integer():
		print(int(c * k * k))
	else:
		m = s % c
		k = s // c
		print(int(k * k * (c - m) + (k + 1) * (k + 1) * m))


for z in range(int(input())):
	(a, b) = map(int, input().split())
	full = b // a
	one = b % a
	ans = (full + 1) ** 2 * one + full ** 2 * (a - one)
	print(ans)


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	if c >= s:
		print(s)
	elif s % c == 0:
		print(max(s, (s // c) ** 2 * c))
	else:
		k = s // c + 1
		s -= k
		c -= 1
		sum = k ** 2
		while s % c != 0:
			s -= k
			sum += k ** 2
			c -= 1
		print(sum + (s // c) ** 2 * c)


n = int(input())
e = [[int(i) for i in input().split()] for i in range(n)]
for i in range(n):
	b = e[i][0]
	a = e[i][1]
	z = a // b
	r = a % b
	print(z ** 2 * (b - r) + (z + 1) ** 2 * r)


n = int(input())
total = 0
import math
for i in range(n):
	(x, y) = map(int, input().split())
	r = y // x
	if y <= x:
		print(y)
	elif y % x == 0:
		print(y // x * (y // x) * x)
	else:
		t = y // x
		r = y % x
		total = 0
		for i in range(r):
			total += (t + 1) * (t + 1)
		for i in range(x - r):
			total += t * t
		print(total)


n = int(input())
for _ in range(n):
	(c, s) = map(int, input().split())
	rem = s % c
	quo = s // c
	ans = (c - rem) * quo * quo + rem * (quo + 1) * (quo + 1)
	print(ans)


t = int(input())
for _ in range(t):
	(c, summ) = [int(x) for x in input().split()]
	avg = summ // c
	cntsWithAvgPlusOne = summ % c
	cntsWithAvg = c - cntsWithAvgPlusOne
	ans = cntsWithAvg * avg ** 2 + cntsWithAvgPlusOne * (avg + 1) ** 2
	print(ans)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	tut = b // a
	uff = b % a
	s = tut * tut * (a - uff) + (tut + 1) * (tut + 1) * uff
	print(s)


n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	if c == 1:
		print(s ** 2)
	else:
		i = 1
		if i * c >= s:
			print(s)
		else:
			while 1:
				if i * c == s:
					print(i ** 2 * c)
					break
				elif i * c > s:
					temp = i * c - s
					print(i ** 2 * (c - temp) + (i - 1) ** 2 * temp)
					break
				else:
					i += 1


n = int(input())
while n > 0:
	(c, s) = [int(x) for x in input().split()]
	ans = 0
	z = c - s % c
	ans += z * (s // c) ** 2
	z = c - z
	ans += z * (s // c + 1) ** 2
	print(ans)
	n -= 1


from math import ceil
n = int(input())
for i in range(n):
	(c, s) = map(int, input().split())
	temp = int(ceil(s / c)) ** 2 * (s % c) + (s // c) ** 2 * (c - s % c)
	print(temp)


import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
while n:
	(a, b) = get_ints()
	print(b % a * (b // a + 1) ** 2 + (a - b % a) * (b // a) ** 2)
	n -= 1


for _ in range(int(input())):
	(c, s) = map(int, input().split())
	rem = s % c
	qt = s // c
	print(rem * (s // c + 1) ** 2 + (c - rem) * (s // c) ** 2)


import sys
n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	sec = y // x + (1 if y % x else 0)
	ans = 0
	s = 0
	firstFlag = True
	for i in range(x):
		ans += sec * sec
		s += sec
		if firstFlag and (sec - 1) * (x - i - 1) >= y - s:
			firstFlag = False
			sec -= 1
	print(ans)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
for _ in range(int(input())):
	(h, rm) = map(int, input().split())
	a = [0] * h
	if h >= rm:
		print(rm)
		continue
	for i in range(h):
		z = rm // h
		a[i] = pow(z, 2)
		h -= 1
		rm -= z
	print(sum(a))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	cost = (b // a + 1) ** 2 * (b % a) + (b // a) ** 2 * (a - b % a)
	print(cost)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	print((b // a + 1) ** 2 * (b % a) + (a - b % a) * (b // a) ** 2)


n = int(input())
for _ in range(n):
	(c, s) = list(map(int, input().split()))
	a = s // c
	r = s % c
	print((c - r) * a ** 2 + r * (a + 1) ** 2)


def main():
	t = int(input())
	for tc in range(t):
		(n, k) = map(int, input().split())
		ar = [int(k / n)] * n
		rem = k % n
		for i in range(len(ar)):
			if rem == 0:
				break
			ar[i] += 1
			rem -= 1
		ans = 0
		for i in range(len(ar)):
			ans += ar[i] * ar[i]
		print(ans)
main()


n = int(input())
for _ in range(n):
	(c, sum) = [int(i) for i in input().split()]
	if c == 1:
		print(sum ** 2)
	elif sum == 1:
		print(1)
	else:
		res = 0
		while c > 0:
			res += (sum // c) ** 2
			sum -= sum // c
			c -= 1
		print(res)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b:
		print(b)
	else:
		s = 0
		s += (b // a + 1) ** 2 * (b % a)
		s += (b // a) ** 2 * (a - b % a)
		print(s)


n = int(input())
while n > 0:
	n -= 1
	(a, b) = map(int, input().split())
	c = b // a
	if c == b * a:
		print(a * c ** 2)
	else:
		summ = 0
		d = b - a * c
		summ += d * (c + 1) ** 2 + (a - d) * c ** 2
		print(summ)


n = int(input())
for i in range(n):
	(ci, sumi) = list(map(int, input().split()))
	q = sumi // ci
	r = sumi % ci
	res = q ** 2 * (ci - r) + r * (q + 1) ** 2
	print(res)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n == 1:
		print(m ** 2)
	elif n >= m:
		print(m)
	elif m % n == 0:
		print((m // n) ** 2 * n)
	else:
		j = (m + n - 1) // n
		r = j * n - m
		print(j ** 2 * (n - r) + (j - 1) ** 2 * r)


for _ in range(int(input())):
	(rads, sum) = map(int, input().split())
	(normal_size, extended_num) = divmod(sum, rads)
	print((rads - extended_num) * normal_size ** 2 + extended_num * (normal_size + 1) ** 2)


import math
ans = []
for test in range(int(input())):
	nums = [int(x) for x in input().split(' ')]
	k_sect = math.floor(nums[1] / nums[0])
	rem = nums[1] % nums[0]
	min_cost = k_sect ** 2 * (nums[0] - rem) + (k_sect + 1) ** 2 * rem
	ans.append(min_cost)
for i in ans:
	print(i)


for _ in range(int(input())):
	(limit, k) = map(int, input().split())
	div = k // limit
	mod = k % limit
	cost = div ** 2 * (limit - mod) + (div + 1) ** 2 * mod
	print(cost)


import sys
reader = (map(int, s.split()) for s in sys.stdin)
(n,) = next(reader)
for _ in range(n):
	(m, s) = next(reader)
	c_mean = s // m
	res = s - c_mean * m
	total = (m - res) * c_mean ** 2 + res * (c_mean + 1) ** 2
	print(total)