#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    for (long long i = k; k <= n; i++) {
      long long mini = (k - 1) * (k) / 2;
      long long maxi = (2 * n - k - 1) * k / 2;
      ans = (ans + (maxi - mini)) % 1000000007;
    }
    cout << ans << "\n";
  }
}
