#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void run_case() {
  int c, sum;
  cin >> c >> sum;
  vector<int> v;
  for (int i = 0; i < c; i++) {
    v.push_back(sum / c);
  }
  int i = 0;
  int rem = sum % c;
  while (rem--) {
    v[i++] += 1;
  }
  long long ans = 0;
  for (int i = 0; i < c; i++) {
    ans += (long long)v[i] * v[i];
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt = 1;
  cin >> tt;
  while (tt--) {
    run_case();
  }
  return 0;
}
