#include <bits/stdc++.h>
using namespace std;
int n;
int c, sum;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c >> sum;
    int v = sum / c, r = sum % c;
    int res = 0;
    for (int j = 1; j <= r; j++) res += 2 * v + 1;
    for (int j = 1; j <= c; j++) res += v * v;
    cout << res << "\n";
  }
  return 0;
}
