#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int c, sum;
    scanf("%d%d", &c, &sum);
    int p = sum / c;
    vector<int> v;
    for (int i = 0; i < c; i++) v.push_back(p);
    int d = sum - p * c;
    for (int i = 0; i < c; i++) {
      if (d == 0) break;
      d--;
      v[i]++;
    }
    long long ans = 0;
    for (int i = 0; i < c; i++) {
      ans += v[i] * v[i];
    }
    printf("%lld\n", ans);
  }
}
