#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long rad, sec;
    cin >> rad >> sec;
    if (sec % rad == 0) {
      cout << rad * (sec / rad) * (sec / rad) << "\n";
    } else {
      int r = sec % rad;
      long long cost = r * ((sec / rad) + 1) * ((sec / rad) + 1) +
                       (rad - r) * (sec / rad) * (sec / rad);
      cout << cost << "\n";
    }
  }
  return 0;
}
