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