#include <bits/stdc++.h>
using namespace std;
void fun(char ch, bool a[]) {
  if (ch == 'a' || ch == 'b' || ch == 'c') a[ch - 'a'] = 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  for (cin >> t; t--;) {
    long long a, b, n, k;
    cin >> a >> b;
    k = b / a;
    n = b % a;
    cout << k * k * (a - n) + (k + 1) * (k + 1) * n << '\n';
  }
  return 0;
}
