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