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