#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    long long c, Sum;
    cin >> c >> Sum;
    long long x = Sum / c;
    long long y = Sum % c;
    long long Ans = y * (x + 1) * (x + 1) + (c - y) * x * x;
    cout << Ans << endl;
  }
}
