#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long ans = (long long)ceil((double)b / (double)a);
    long long vv = abs(ans * a - b);
    cout << vv * (ans - 1) * (ans - 1) + (a - vv) * ans * ans << '\n';
  }
  return 0;
}
