#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, a, b;
  cin >> t;
  while (t--) {
    long long s = 0;
    cin >> a >> b;
    long long u = b / a, v = b % a;
    s = (a - v) * u * u + v * (1 + u) * (1 + u);
    cout << s << endl;
  }
  return 0;
}
