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