#include <bits/stdc++.h>
using namespace std;
int Q, K, l, r;
long long dp[100001];
struct STnode {
  long long sum;
  void merge(STnode& left, STnode& right) {
    sum = ((left.sum % 1000000007) + (right.sum % 1000000007)) % 1000000007;
  }
};
STnode ST[4 * 100001];
void dpSubSet() {
  for (int i = 0; i < K; i++) dp[i] = 0;
  for (int i = K; i < 100001; i++) {
    dp[i] = ((dp[i - 1] % 1000000007) + (dp[max(i - K, 0)] % 1000000007) + 1) %
            1000000007;
  }
  for (int i = 1; i < 100001; i++) dp[i] = (dp[i] + 1) % 1000000007;
}
void buildSegmentTree(int node = 0, int l = 0, int r = 100001 - 1) {
  if (l == r)
    ST[node].sum = dp[l];
  else {
    int med = (l + r) >> 1;
    buildSegmentTree(2 * node + 1, l, med);
    buildSegmentTree(2 * node + 2, med + 1, r);
    ST[node].merge(ST[2 * node + 1], ST[2 * node + 2]);
  }
}
STnode query(int i, int j, int node = 0, int l = 0, int r = 100001 - 1) {
  if (i == l && j == r) return ST[node];
  int med = (l + r) >> 1;
  if (j <= med)
    return query(i, j, 2 * node + 1, l, med);
  else if (i > med)
    return query(i, j, 2 * node + 2, med + 1, r);
  else {
    STnode left = query(i, med, 2 * node + 1, l, med);
    STnode right = query(med + 1, j, 2 * node + 2, med + 1, r);
    STnode n;
    n.merge(left, right);
    return n;
  }
}
int main() {
  STnode x;
  scanf("%d %d", &Q, &K);
  dpSubSet();
  buildSegmentTree();
  for (int q = 0; q < Q; q++) {
    scanf("%d %d", &l, &r);
    x = query(l, r);
    printf("%I64d\n", x.sum);
  };
}
