#include <bits/stdc++.h>
using namespace std;
int t, k;
int a, b;
int dp[100005];
int sum[100005];
int main() {
  scanf("%d%d", &t, &k);
  for (int i = 1; i <= k - 1; i++) {
    dp[i] = 1;
  }
  dp[k] = 2;
  for (int i = k + 1; i <= 100000; i++) {
    dp[i] = (dp[i - 1] + dp[i - k]) % 1000000007;
  }
  for (int i = 1; i <= 100000; i++) {
    sum[i] = (sum[i - 1] + dp[i]) % 1000000007;
  }
  for (int i = 0; i < t; i++) {
    scanf("%d%d", &a, &b);
    printf("%d\n", (sum[b] - sum[a - 1] + 1000000007) % 1000000007);
  }
}
