#include <bits/stdc++.h>
using namespace std;
long long dp[100001];
long long sum1[100001];
int main() {
  long long t, k, i, a, b, sum, pro = 1;
  cin >> t >> k;
  if (k == 1) {
    for (i = 1; i <= 100000; i++) {
      pro = pro * 2;
      if (pro >= 1000000007) pro = pro % 1000000007;
      dp[i] = pro;
      sum1[i] = sum1[i - 1] + dp[i];
      if (sum1[i] >= 1000000007) sum1[i] = sum1[i] % 1000000007;
    }
  }
  if (k > 1) {
    for (i = 1; i < k; i++) dp[i] = 1;
    dp[k] = 2;
    for (i = k + 1; i <= 100000; i++) {
      dp[i] = dp[i - 1] + dp[i - k];
      if (dp[i] >= 1000000007) dp[i] = dp[i] % 1000000007;
    }
    for (i = 1; i <= 100000; i++) {
      sum1[i] = sum1[i - 1] + dp[i];
      if (sum1[i] >= 1000000007) sum1[i] = sum1[i] % 1000000007;
    }
  }
  while (t--) {
    cin >> a >> b;
    sum = 0;
    if (k == 0)
      sum = b - a + 1;
    else if (k >= 1) {
      sum = sum1[b] - sum1[a - 1];
      if (sum < 0) sum = sum + 1000000007;
    }
    cout << sum << endl;
  }
}
