#include <bits/stdc++.h>
using namespace std;
int dp[100005], sum[100005];
int main() {
  int n, k;
  cin >> n >> k;
  memset(dp, 0, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  dp[0] = 1;
  sum[0] = 0;
  for (int i = 1; i <= 100000; i++) {
    if (i >= k)
      dp[i] = (dp[i - 1] + dp[i - k]) % 1000000007;
    else
      dp[i] = dp[i - 1];
    sum[i] = (sum[i - 1] + dp[i]) % 1000000007;
  }
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    cout << (sum[b] - sum[a - 1] + 1000000007) % 1000000007 << endl;
  }
  return 0;
}
