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