#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > csum;
void npt() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c, sum;
    cin >> c >> sum;
    csum.push_back({c, sum});
  }
}
int gtans(pair<int, int> p) {
  int res = 0;
  vector<int> r;
  while (p.first) {
    int tmp = (p.second + p.first - 1) / p.first;
    r.push_back(tmp);
    p.second -= tmp;
    p.first--;
  }
  for (auto i : r) res += i * i;
  return res;
}
void slv() {
  for (auto i : csum) {
    if (i.first >= i.second)
      cout << i.second << endl;
    else
      cout << gtans(i) << endl;
  }
}
int main() {
  npt();
  slv();
  return 0;
}
