#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int c, s;
    int total;
    cin >> c >> s;
    if (s % c > 0)
      total =
          (s / c + 1) * (s / c + 1) * (s % c) + (s / c) * (s / c) * (c - s % c);
    else
      total = (s / c) * (s / c) * c;
    cout << total << "\n";
  }
  return 0;
}
