#include <bits/stdc++.h>
using namespace std;
void my_file_in_out() {
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
const int M = 1e9 + 7;
void solve() {
  int c, w;
  cin >> c >> w;
  vector<long long> a(c, w / c);
  c = w % c;
  while (c) a[--c]++;
  long long sum = 0;
  for (long long x : a) sum += (x * x);
  cout << sum << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
