#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int to(int x, int y) { return (x * 60) + (y); }
string to_string(long long a) {
  stringstream ss;
  ss << a;
  string str = ss.str();
  return str;
}
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int nCr(long long int x, long long int y) {
  long long int sum = 1;
  for (int i = 1; i <= y; i++) {
    sum *= x;
    x--;
    sum /= i;
  }
  return sum;
}
long double dist(pair<double, pair<double, pair<double, double> > > a,
                 pair<double, pair<double, pair<double, double> > > b) {
  return (
      ((a.first - b.first) * (a.first - b.first)) +
      ((a.second.first - b.second.first) * (a.second.first - b.second.first)) +
      ((a.second.second.first - b.second.second.first) *
       (a.second.second.first - b.second.second.first)));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    if (n == m)
      cout << n * (n + 1) / 2 << endl;
    else if (m)
      cout << nCr(n, m) + m << endl;
    else
      cout << 0 << endl;
  }
  cout << endl;
  return 0;
}
