#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int L = 1e5 + 1;
const ll MOD = 1e9 + 7;
const int INF = (int)MOD;
int n, c, sum;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c >> sum;
    int m = sum / c;
    cout << m * m * (c - sum % c) + (m + 1) * (m + 1) * (sum % c) << '\n';
  }
  return 0;
}
