#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool prime(long long int n) {
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long binexpm(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long binexp(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int tttt;
  cin >> tttt;
  while (tttt--) {
    long long int c, sum;
    cin >> c >> sum;
    if (c >= sum)
      cout << sum << "\n";
    else {
      if (c == 1) {
        cout << sum * sum << "\n";
      } else {
        if (sum % c == 0) {
          long long int x = sum / c;
          cout << (c * x * x) << "\n";
        } else {
          double x = sum / c;
          x = floor(x);
          long long int ans = 0;
          while (sum % c != 0) {
            ans += (x * x);
            c--;
            sum -= x;
          }
          long long int y = sum / c;
          ans += c * (y * y);
          cout << ans << "\n";
        }
      }
    }
  }
  return 0;
}
