#include <bits/stdc++.h>
int dp[100010];
int t, k;
int main() {
  scanf("%d%d", &t, &k);
  dp[0] = 1;
  for (int i = 1; i < 100010; i++) {
    dp[i] = dp[i - 1];
    if (i >= k) {
      dp[i] += dp[i - k];
    }
    dp[i] %= 1000000007;
  }
  for (int i = 1; i < 100010; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= 1000000007;
  }
  while (t--) {
    int a, b;
    scanf("%d%d", &a, &b);
    int ans = (dp[b] - dp[a - 1]) % 1000000007;
    if (ans < 0) {
      ans += 1000000007;
    }
    printf("%d\n", ans);
  }
  return 0;
}
