#include <bits/stdc++.h>
using namespace std;
int a[10050];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      a[i] = m / n;
    }
    for (int i = 0; i < m % n; i++) {
      a[i]++;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum = sum + a[i] * a[i];
    }
    cout << sum << endl;
  }
}
