#include <bits/stdc++.h>
using namespace std;
const int N = 2e5, inf = 1e9;
long long s, c, T;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> c >> s;
    long long temp1 = s / c, temp2 = s % c;
    cout << (c - temp2) * (long long)pow(temp1, 2) +
                temp2 * (long long)pow(temp1 + 1, 2)
         << "\n";
  }
  return 0;
}
