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