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