#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c, summ, ans = 0;
  cin >> n;
  while (n--) {
    ans = 0;
    cin >> c >> summ;
    if (summ <= c) {
      cout << summ << endl;
    } else {
      long long temp = summ;
      long long r = ceil(float(summ) / c);
      while (temp >= r) {
        r = ceil(float(temp) / c);
        ans += r * r;
        temp -= r;
        c--;
      }
      if (c)
        cout << ans + temp * temp << endl;
      else
        cout << ans << endl;
    }
  }
}
