import math T = int(input()) for t in range(T): X , A = map(int,input().split()) dp = [0] + [10**20] * A XB = int(X**0.5) + 100 XA = min(max(1,A-100),max(1,int(X**0.5)-100)) for i in range(A): flag = 0 for j in range(XA,XB): if i + j > A: continue tmp = dp[i] + j * j + X if dp[i + j] > tmp: dp[i + j] = tmp flag = 1 #if flag == 0: # break #print(dp) print(dp[-1])