#include <bits/stdc++.h>
template <class A>
void transpose(std::vector<std::vector<A>>& v) {
  std::vector<std::vector<A>> result((int)v[0].size(),
                                     std::vector<A>((int)v.size()));
  for (int i = 0; i < (int)v.size(); i++) {
    for (int j = 0; j < (int)v[0].size(); j++) {
      result[j][i] = v[i][j];
    }
  }
  v = result;
}
std::string to_string(const std::string& s) { return '"' + s + '"'; }
std::string to_string(const char* s) { return to_string((std::string)s); }
std::string to_string(const bool& b) { return (b ? "true" : "false"); }
std::string to_string(const char& c) { return (std::string) "'" + c + "'"; }
std::string to_string(const std::vector<bool>& v) {
  std::string ret = "{" + to_string(v.front());
  for (int i = 1; i < static_cast<int>(v.size()); i++) {
    ret += ", " + to_string(v[i]);
  }
  return ret + "}";
}
template <typename A>
std::string to_string(A x) {
  return std::to_string(x);
}
template <typename A, typename B>
std::string to_string(std::pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
std::string to_string(const std::vector<A>& v) {
  std::string ret = "{" + to_string(v.front());
  for (int i = 1; i < static_cast<int>(v.size()); i++) {
    ret += ", " + to_string(v[i]);
  }
  return ret + "}";
}
template <typename A>
std::string to_string(const std::set<A>& st) {
  if (st.empty()) {
    return "[empty]";
  }
  auto it = st.begin();
  std::string ret = "[" + to_string(*it);
  it++;
  for (; it != st.end(); it++) {
    ret += ", " + to_string(*it);
  }
  return ret + "]";
}
template <typename A>
std::string to_string(const std::unordered_set<A>& st) {
  if (st.empty()) {
    return "[empty]";
  }
  auto it = st.begin();
  std::string ret = "[" + to_string(*it);
  it++;
  for (; it != st.end(); it++) {
    ret += ", " + to_string(*it);
  }
  return ret + "]";
}
template <typename A, typename B>
std::string to_string(const std::map<A, B>& mp) {
  if (mp.empty()) {
    return "[empty]";
  }
  auto it = mp.begin();
  std::string ret =
      "[(" + to_string((*it).first) + ": " + to_string((*it).second) + ")";
  it++;
  for (; it != mp.end(); it++) {
    ret +=
        ", (" + to_string((*it).first) + ": " + to_string((*it).second) + ")";
  }
  return ret + "]";
}
template <typename A, typename B>
std::string to_string(const std::unordered_map<A, B>& mp) {
  if (mp.empty()) {
    return "[empty]";
  }
  auto it = mp.begin();
  std::string ret =
      "[(" + to_string((*it).first) + ": " + to_string((*it).second) + ")";
  it++;
  for (; it != mp.end(); it++) {
    ret +=
        ", (" + to_string((*it).first) + ": " + to_string((*it).second) + ")";
  }
  return ret + "]";
}
template <typename A>
std::string to_string(const std::queue<A>& q) {
  if (q.empty()) {
    return "[empty]";
  }
  std::queue<A> bckp = q;
  std::string ret = "[" + to_string(bckp.front());
  bckp.pop();
  while (!bckp.empty()) {
    A tp = bckp.front();
    bckp.pop();
    ret += ", " + to_string(tp);
  }
  return ret + "]";
}
template <typename A>
std::string to_string(const std::priority_queue<A>& pq) {
  if (pq.empty()) {
    return "[empty]";
  }
  std::priority_queue<A> bckp = pq;
  std::string ret = "[" + to_string(bckp.top());
  bckp.pop();
  while (!bckp.empty()) {
    A tp = bckp.top();
    bckp.pop();
    ret += ", " + to_string(tp);
  }
  return ret + "]";
}
template <typename A>
std::string to_string(const std::stack<A>& stck) {
  if (stck.empty()) {
    return "[empty]";
  }
  std::stack<A> bckp = stck;
  std::string ret = "[" + to_string(bckp.top());
  bckp.pop();
  while (!bckp.empty()) {
    A tp = bckp.top();
    bckp.pop();
    ret += ", " + to_string(tp);
  }
  return ret + "]";
}
void debug_out() { std::cerr << std::endl; }
template <typename H, typename... T>
void debug_out(H h, T... t) {
  std::cout << " " << to_string(h);
  debug_out(t...);
}
template <typename T = int>
class Graph_T {
 public:
  struct Edge {
    int from, to;
    T weight;
  };
  std::vector<Edge> edges;
  std::vector<std::vector<int>> adj;
  int size;
  Graph_T(int SIZE) : size(SIZE) { adj.resize(size); }
  virtual int add(int from, int to, T weight) = 0;
};
template <typename T = int>
class Tree : public Graph_T<T> {
 public:
  using Graph_T<T>::edges;
  using Graph_T<T>::adj;
  using Graph_T<T>::size;
  bool assert_tree;
  Tree(int SIZE, bool ASSERT_TREE = true)
      : Graph_T<T>(SIZE), assert_tree(ASSERT_TREE) {}
  int add(int from, int to, T weight = 1) {
    assert(0 <= from && from < size && 0 <= to && to < size);
    int ID = (int)edges.size();
    if (assert_tree) {
      assert(ID < size - 1);
    }
    adj[from].push_back(ID);
    adj[to].push_back(ID);
    edges.push_back({from, to, weight});
    return ID;
  }
  bool istree(int node = 0, int parent = -1) {
    assert(size);
    static std::vector<bool> vis;
    if (!node && parent == -1) {
      vis.clear();
      vis.resize(size, false);
    }
    vis[node] = true;
    bool ok = true;
    for (const int& x : adj[node]) {
      int to = edges[x].from ^ edges[x].to ^ node;
      if (to == parent) {
        continue;
      }
      if (vis[to]) {
        return false;
      }
      ok = ok & istree(to, node);
    }
    if (!node && parent == -1) {
      ok = ok & (std::count((vis).begin(), (vis).end(), true) == size);
    }
    return ok;
  }
  T pathUV(int u, int v) {
    std::priority_queue<std::pair<T, int>> pq;
    std::vector<bool> vis(size, false);
    pq.push(std::make_pair(0, u));
    vis[u] = true;
    while (!pq.empty()) {
      auto now = pq.top();
      pq.pop();
      if (now.second == v) return -now.first;
      for (const int& x : adj[now.second]) {
        int to = edges[x].from ^ edges[x].to ^ now.second;
        if (!vis[to]) {
          pq.push(std::make_pair(now.first - edges[x].weight, to));
          vis[to] = true;
        }
      }
    }
    return (T)-1;
  }
};
template <typename T = int>
class D_Tree : public Graph_T<T> {
 public:
  using Graph_T<T>::edges;
  using Graph_T<T>::adj;
  using Graph_T<T>::size;
  D_Tree(int SIZE) : Graph_T<T>(SIZE) {}
  int add(int from, int to, T weight = 1) {
    assert(0 <= from && from < size && 0 <= to && to < size);
    int ID = (int)edges.size();
    adj[from].push_back(ID);
    edges.push_back({from, to, weight});
    return ID;
  }
  bool istree(int node = 0) {
    assert(size);
    static std::vector<bool> vis;
    if (!node) {
      vis.clear();
      vis.resize(size, false);
    }
    vis[node] = true;
    bool ok = true;
    for (const int& x : adj[node]) {
      int to = edges[x].to;
      if (vis[to]) {
        return false;
      }
      ok = ok & istree(to);
    }
    if (!node) {
      ok = ok & (std::count((vis).begin(), (vis).end(), true) == size);
    }
    return ok;
  }
  T pathUV(int u, int v) {
    std::priority_queue<std::pair<T, int>> pq;
    std::vector<bool> vis(size, false);
    pq.push(std::make_pair(0, u));
    vis[u] = true;
    while (!pq.empty()) {
      auto now = pq.top();
      pq.pop();
      if (now.second == v) return -now.first;
      for (const int& x : adj[now.second]) {
        int to = edges[x].to;
        if (!vis[to]) {
          pq.push(std::make_pair(now.first - edges[x].weight, to));
          vis[to] = true;
        }
      }
    }
    return (T)-1;
  }
};
template <typename T = int>
class Forest : public Graph_T<T> {
 public:
  using Graph_T<T>::edges;
  using Graph_T<T>::adj;
  using Graph_T<T>::size;
  bool assert_forest;
  Forest(int SIZE, bool ASSERT_FOREST = true)
      : Graph_T<T>(SIZE), assert_forest(ASSERT_FOREST) {}
  int add(int from, int to, T weight = 1) {
    assert(0 <= from && from < size && 0 <= to && to < size);
    int ID = (int)edges.size();
    if (assert_forest) {
      assert(ID < size - 1);
    }
    adj[from].push_back(ID);
    adj[to].push_back(ID);
    edges.push_back({from, to, weight});
    return ID;
  }
  bool istree(int node = 0, int parent = -1) {
    assert(size);
    static std::vector<bool> vis;
    if (!node && parent == -1) {
      vis.clear();
      vis.resize(size, false);
    }
    vis[node] = true;
    bool ok = true;
    for (const int& x : adj[node]) {
      int to = edges[x].from ^ edges[x].to ^ node;
      if (to == parent) {
        continue;
      }
      if (vis[to]) {
        return false;
      }
      ok = ok & istree(to, node);
    }
    if (!node && parent == -1) {
      ok = ok & (std::count((vis).begin(), (vis).end(), true) == size);
    }
    return ok;
  }
  bool isforest() {
    assert(size);
    std::vector<bool> vis(size, false);
    for (int i = 0; i < size; i++) {
      if (!vis[i]) {
        if (!m_isforest(vis, i)) {
          return false;
        }
      }
    }
    return true;
  }
  T pathUV(int u, int v) {
    std::priority_queue<std::pair<T, int>> pq;
    std::vector<bool> vis(size, false);
    pq.push(std::make_pair(0, u));
    vis[u] = true;
    while (!pq.empty()) {
      auto now = pq.top();
      pq.pop();
      if (now.second == v) return -now.first;
      for (const int& x : adj[now.second]) {
        int to = edges[x].from ^ edges[x].to ^ now.second;
        if (!vis[to]) {
          pq.push(std::make_pair(now.first - edges[x].weight, to));
          vis[to] = true;
        }
      }
    }
    return (T)-1;
  }

 private:
  bool m_isforest(std::vector<bool>& vis, int node, int parent = -1) {
    vis[node] = true;
    for (const int& x : adj[node]) {
      int to = edges[x].from ^ edges[x].to ^ node;
      if (to == parent) {
        continue;
      }
      if (vis[to]) {
        return false;
      }
      if (!m_isforest(vis, to, node)) {
        return false;
      }
    }
    return true;
  }
};
template <typename T = int>
class D_Forest : public Graph_T<T> {
 public:
  using Graph_T<T>::edges;
  using Graph_T<T>::adj;
  using Graph_T<T>::size;
  D_Forest(int SIZE) : Graph_T<T>(SIZE) {}
  int add(int from, int to, T weight = 1) {
    assert(0 <= from && from < size && 0 <= to && to < size);
    int ID = (int)edges.size();
    adj[from].push_back(ID);
    edges.push_back({from, to, weight});
    return ID;
  }
  bool istree(int node = 0) {
    assert(size);
    static std::vector<bool> vis;
    if (!node) {
      vis.clear();
      vis.resize(size, false);
    }
    vis[node] = true;
    bool ok = true;
    for (const int& x : adj[node]) {
      int to = edges[x].to;
      if (vis[to]) {
        return false;
      }
      ok = ok & istree(to);
    }
    if (!node) {
      ok = ok & (std::count((vis).begin(), (vis).end(), true) == size);
    }
    return ok;
  }
  bool isforest() {
    assert(size);
    std::vector<bool> vis(size, false);
    for (int i = 0; i < size; i++) {
      if (!vis[i]) {
        if (!m_isforest(vis, i)) {
          return false;
        }
      }
    }
    return true;
  }
  T pathUV(int u, int v) {
    std::priority_queue<std::pair<T, int>> pq;
    std::vector<bool> vis(size, false);
    pq.push(std::make_pair(0, u));
    vis[u] = true;
    while (!pq.empty()) {
      auto now = pq.top();
      pq.pop();
      if (now.second == v) return -now.first;
      for (const int& x : adj[now.second]) {
        int to = edges[x].to;
        if (!vis[to]) {
          pq.push(std::make_pair(now.first - edges[x].weight, to));
          vis[to] = true;
        }
      }
    }
    return (T)-1;
  }

 private:
  bool m_isforest(std::vector<bool>& vis, int node, int parent = -1) {
    vis[node] = true;
    for (const int& x : adj[node]) {
      int to = edges[x].to;
      if (vis[to]) {
        return false;
      }
      if (!m_isforest(vis, to, node)) {
        return false;
      }
    }
    return true;
  }
};
template <typename T = int>
class Graph : public Graph_T<T> {
 public:
  using Graph_T<T>::edges;
  using Graph_T<T>::adj;
  using Graph_T<T>::size;
  Graph(int SIZE) : Graph_T<T>(SIZE) {}
  int add(int from, int to, T weight = 1) {
    assert(0 <= from && from < size && 0 <= to && to < size);
    int ID = (int)edges.size();
    adj[from].push_back(ID);
    adj[to].push_back(ID);
    edges.push_back({from, to, weight});
    return ID;
  }
  bool istree(int node = 0, int parent = -1) {
    assert(size);
    static std::vector<bool> vis;
    if (!node && parent == -1) {
      vis.clear();
      vis.resize(size, false);
    }
    vis[node] = true;
    bool ok = true;
    for (const int& x : adj[node]) {
      int to = edges[x].from ^ edges[x].to ^ node;
      if (to == parent) {
        continue;
      }
      if (vis[to]) {
        return false;
      }
      ok = ok & istree(to, node);
    }
    if (!node && parent == -1) {
      ok = ok & (std::count((vis).begin(), (vis).end(), true) == size);
    }
    return ok;
  }
  bool isforest() {
    assert(size);
    std::vector<bool> vis(size, false);
    for (int i = 0; i < size; i++) {
      if (!vis[i]) {
        if (!m_isforest(vis, i)) {
          return false;
        }
      }
    }
    return true;
  }
  T pathUV(int u, int v) {
    std::priority_queue<std::pair<T, int>> pq;
    std::vector<bool> vis(size, false);
    pq.push(std::make_pair(0, u));
    vis[u] = true;
    while (!pq.empty()) {
      auto now = pq.top();
      pq.pop();
      if (now.second == v) return -now.first;
      for (const int& x : adj[now.second]) {
        int to = edges[x].from ^ edges[x].to ^ now.second;
        if (!vis[to]) {
          pq.push(std::make_pair(now.first - edges[x].weight, to));
          vis[to] = true;
        }
      }
    }
    return (T)-1;
  }

 private:
  bool m_isforest(std::vector<bool>& vis, int node, int parent = -1) {
    vis[node] = true;
    for (const int& x : adj[node]) {
      int to = edges[x].from ^ edges[x].to ^ node;
      if (to == parent) {
        continue;
      }
      if (vis[to]) {
        return false;
      }
      if (!m_isforest(vis, to, node)) {
        return false;
      }
    }
    return true;
  }
};
template <typename T = int>
class D_Graph : public Graph_T<T> {
 public:
  using Graph_T<T>::edges;
  using Graph_T<T>::adj;
  using Graph_T<T>::size;
  D_Graph(int SIZE) : Graph_T<T>(SIZE) {}
  int add(int from, int to, T weight = 1) {
    assert(0 <= from && from < size && 0 <= to && to < size);
    int ID = (int)edges.size();
    adj[from].push_back(ID);
    edges.push_back({from, to, weight});
    return ID;
  }
  bool istree(int node = 0) {
    assert(size);
    static std::vector<bool> vis;
    if (!node) {
      vis.clear();
      vis.resize(size, false);
    }
    vis[node] = true;
    bool ok = true;
    for (const int& x : adj[node]) {
      int to = edges[x].to;
      if (vis[to]) {
        return false;
      }
      ok = ok & istree(to);
    }
    if (!node) {
      ok = ok & (std::count((vis).begin(), (vis).end(), true) == size);
    }
    return ok;
  }
  bool isforest() {
    assert(size);
    std::vector<bool> vis(size, false);
    for (int i = 0; i < size; i++) {
      if (!vis[i]) {
        if (!m_isforest(vis, i)) {
          return false;
        }
      }
    }
    return true;
  }
  T pathUV(int u, int v) {
    std::priority_queue<std::pair<T, int>> pq;
    std::vector<bool> vis(size, false);
    pq.push(std::make_pair(0, u));
    vis[u] = true;
    while (!pq.empty()) {
      auto now = pq.top();
      pq.pop();
      if (now.second == v) return -now.first;
      for (const int& x : adj[now.second]) {
        int to = edges[x].to;
        if (!vis[to]) {
          pq.push(std::make_pair(now.first - edges[x].weight, to));
          vis[to] = true;
        }
      }
    }
    return (T)-1;
  }

 private:
  bool m_isforest(std::vector<bool>& vis, int node, int parent = -1) {
    vis[node] = true;
    for (const int& x : adj[node]) {
      int to = edges[x].to;
      if (vis[to]) {
        return false;
      }
      if (!m_isforest(vis, to, node)) {
        return false;
      }
    }
    return true;
  }
};
void solv(const int curt);
const bool isT = true;
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int t = 1;
  if (isT) {
    std::cin >> t;
  }
  for (int i = 1; i <= t; i++) {
    solv(i);
  }
  return 0;
}
void solv(const int curt) {
  long long n, m;
  std::cin >> n >> m;
  std::cout << ((n * (n + 1LL)) / 2LL) -
                   ((m + 1LL) * (((n - m) / (m + 1LL)) *
                                 (((n - m) / (m + 1LL)) + 1LL) / 2LL)) -
                   (((n - m) % (m + 1LL)) * (((n - m) / (m + 1LL)) + 1LL))
            << "\n";
}
