import java.util.*; import java.util.stream.*; public class Main { static Scanner scan; public static void test(int t) { int res = 0; int x = scan.nextInt(); //clumsines int a = scan.nextInt(); //monster hp long mmp = -1; for (int n = 1; n < a + 1; n++) { int mS = a / n; int nMS = a % n; // nMS * (mS + 1) + (n - nMS) * mS = a // calc mp long mp = ((long)n - nMS) * ((long)mS * mS + x) + (long)nMS * ((long)(mS+1)*(mS+1) + x); if ((mmp == -1) || (mmp > mp)) { mmp = mp; } } System.out.println(mmp); } public static void main(String []args) { scan = new Scanner(System.in); int t = scan.nextInt(); IntStream.range(0,t).forEach(Main::test); } }