#include <bits/stdc++.h>
clock_t time_p = clock();
using namespace std;
const int N = 2e5 + 1, mod = 998244353;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
      cout << 1LL * b * b / a << "\n";
    } else {
      int x = b % a, y = a - x;
      long long int res =
          1LL * x * (b / a + 1) * (b / a + 1) + 1LL * y * (b / a) * (b / a);
      cout << res << "\n";
    }
  }
  cerr << "\nTime Taken : " << (float)(clock() - time_p) / CLOCKS_PER_SEC
       << "\n";
  ;
}
