from collections import deque import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict from functools import lru_cache # for AtCoder Easy test if __file__ == 'prog.py': pass else: sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') input = sys.stdin.readline def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input()[:-1] T = int(input()) for _ in range(T): X, A = readints() ans = float('inf') for i in range(1, A + 1): p, q = divmod(A, i) ans = min(ans, p * p * (i - q) + (p + 1) * (p + 1) * q + X * i) print(ans)