#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 10010;
int c[N], sum[N], sol[N];
int main() {
  int n;
  cin >> n;
  for (int(i) = 1; (i) <= (int)n; (i)++) cin >> c[i] >> sum[i];
  for (int(i) = 1; (i) <= (int)n; (i)++) {
    long long ans = 0;
    if (sum[i] <= c[i])
      ans = sum[i];
    else {
      if (c[i] == 1)
        ans = sum[i] * sum[i];
      else if (sum[i] % c[i] == 0)
        ans = c[i] * (sum[i] / c[i]) * (sum[i] / c[i]);
      else {
        memset(sol, 0, sizeof(sol));
        for (int(j) = 1; (j) <= (int)c[i]; (j)++) sol[j] += sum[i] / c[i];
        int rem = sum[i] % c[i];
        for (int j = 1; rem; j++, rem--) sol[j]++;
        for (int(j) = 1; (j) <= (int)c[i]; (j)++) ans += sol[j] * sol[j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
