#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) {
    long long c, sum;
    cin >> c >> sum;
    vector<long long> R(c, 0);
    long long i = 0;
    while (sum--) {
      R[i]++;
      i++;
      i %= c;
    }
    long long ans = 0;
    for (long long j = 0; j < c; j++) {
      ans += R[j] * R[j];
    }
    cout << ans << endl;
  }
  return 0;
}
