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