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