#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12 + 7;
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    long long c, sum;
    cin >> c >> sum;
    long long d = sum / c;
    long long o = sum % c;
    cout << (d + 1) * (d + 1) * o + (c - o) * d * d << '\n';
  }
  return 0;
}
