#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long int temp = power(a, b / 2);
  if (b % 2 == 0)
    return (temp * temp) % 1000000007;
  else
    (((temp * temp) % 1000000007) * a) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int a, b, c, d, e, f = 998244353, g, h, i, j, k, l, m, n, o, p = 0,
                               q = 0, r, t, u, v, w, x = 0, y, z, temp = 0, s,
                               t1, r1, t2, sum = 0, mi = 0, mx = 0, ans = 0,
                               cnt;
  q = 1;
  cin >> q >> k;
  vector<long long int> fact(1e5 + 5);
  fact[0] = 1;
  for (i = 1; i <= 1e5; i++) {
    if (i < k)
      fact[i] = 1;
    else
      fact[i] = (fact[i - 1] + fact[i - k]) % 1000000007;
  }
  for (i = 1; i < 1e5 + 1; i++) fact[i] = (fact[i - 1] + fact[i]) % 1000000007;
  while (q--) {
    cin >> a >> b;
    long long int cnt = 0;
    cout << (fact[b] - fact[a - 1] + 1000000007) % 1000000007 << endl;
  }
}
