#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c, sum;
    cin >> c >> sum;
    int cntbig = sum % c;
    int lilcost = sum / c;
    int bigcost = lilcost + 1;
    int cntlil = c - cntbig;
    cout << (long long)cntlil * lilcost * lilcost +
                (long long)cntbig * bigcost * bigcost
         << '\n';
  }
}
