#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > graph;
vector<vector<long long int> > colour;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  if (a == 0) return b;
  if (a > b) return gcd(b, a % b);
  return gcd(a, b % a);
}
long long int max(long long int a, long long int b) {
  if (a > b)
    return a;
  else
    return b;
}
long long int mini(long long int a, long long int b) {
  if (a > b)
    return b;
  else
    return a;
}
void swap(long long int &a, long long int &b) {
  long long int temp = a;
  a = b;
  b = temp;
}
int modpower(long long int a, long long int b, long long int c) {
  long long int r = 1;
  a = a % c;
  while (b > 0) {
    if (b % 2 == 1) r = (r * a) % c;
    b = b / 2;
    a = (a * a) % c;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    if (a >= b)
      cout << b << "\n";
    else {
      long long int c[a];
      for (long long int i = 0; i < a; i++) c[i] = 0;
      long long int ind = 0;
      while (b > 0) {
        c[ind]++;
        ind = (ind + 1) % a;
        b--;
      }
      long long int ans = 0;
      for (long long int i = 0; i < a; i++) ans = ans + c[i] * c[i];
      cout << ans << "\n";
    }
  }
}
