#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int c, sum;
    cin >> c >> sum;
    int d = sum / c;
    int rem = sum % c;
    cout << rem * (d + 1) * (d + 1) + (c - rem) * d * d << '\n';
  }
  return 0;
}
