#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
long long n;
long long x, y;
vector<long long> a;
long long ans;
void find_terms(long long c, long long sum) {
  while (sum != 0) {
    if (sum / c != 0) a.push_back(sum / c);
    sum -= sum / c;
    c--;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c, sum;
    cin >> c >> sum;
    find_terms(c, sum);
    for (int i = 0; i < a.size(); i++) {
      ans += pow(a[i], 2);
    }
    a.clear();
    cout << ans << endl;
    ans = 0;
  }
}
