#include <bits/stdc++.h>
using namespace std;
long long int dp[101000];
int main(int argc, char const *argv[]) {
  int t, a, b, k;
  scanf("%d%d", &t, &k);
  dp[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % 1000000007;
    if (i >= k) dp[i] = (dp[i] + dp[i - k]) % 1000000007;
  }
  dp[0] = 0;
  for (int i = 2; i <= 100000; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % 1000000007;
  }
  while (t--) {
    scanf("%d%d", &a, &b);
    long long int ans = (dp[b] - dp[a - 1] + 1000000007) % 1000000007;
    cout << ans << "\n";
  }
  return 0;
}
