#include <bits/stdc++.h>
using namespace std;
int t, a, b;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &a, &b);
    long long t2 = b - b / a * a, c2 = b / a + 1;
    long long t1 = a - t2, c1 = b / a;
    printf("%lld\n", t2 * c2 * c2 + t1 * c1 * c1);
  }
  return 0;
}
