#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= n - 1; i += 1) {
    long long cnt, sum;
    cin >> cnt >> sum;
    long long val = sum / cnt;
    long long rem = sum % cnt;
    cout << val * val * (cnt - rem) + rem * (val + 1) * (val + 1) << endl;
  }
  return 0;
}
