#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int c, s;
    scanf("%d%d", &c, &s);
    int p = s / c;
    int pc = s % c;
    printf("%d\n", p * p * (c - pc) + (p + 1) * (p + 1) * pc);
  }
  return 0;
}
