#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long int n) {
  if (n == 1) return false;
  if (n == 2 || n == 3) return true;
  if (n % 2 == 0) return false;
  for (long long int i = 3; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
void swap(long long int *xp, long long int *yp) {
  long long int t = *xp;
  *xp = *yp;
  *yp = t;
}
set<long long int> SieveOfEratosthenes(long long int n) {
  set<long long int> s;
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (prime[p]) s.insert(p);
  return s;
}
int main() {
  long long int n;
  cin >> n;
  while (n--) {
    long long int c, sum;
    cin >> c >> sum;
    long long int key = sum / c;
    long long int temp = sum % c;
    vector<long long int> v;
    for (long long int i = 0; i < c; i++) v.push_back(key);
    for (long long int i = 0; i < sum % c; i++) v[i] = v[i] + 1;
    long long int ans = 0;
    for (long long int i = 0; i < v.size(); i++) ans += v[i] * v[i];
    cout << ans << endl;
  }
  return 0;
}
