#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int maxn = 209;
const int inf = 100000009;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long tmp = b / a;
    long long hj = b % a;
    cout << (tmp + 1) * (tmp + 1) * hj + (a - hj) * tmp * tmp << endl;
  }
  return 0;
}
