#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const double PI = acos(-1);
FILE* in = stdin;
FILE* out = stdout;
const int MAXN = 200005;
int t, k, a, b, DP[MAXN], S[MAXN];
void eval() {
  for (int i = 0; i < k; i++) {
    DP[i] = 1;
  }
  for (int i = k; i < MAXN; i++) {
    DP[i] = (DP[i - 1] + DP[i - k]) % MOD;
  }
  S[0] = DP[0];
  for (int i = 1; i < MAXN; i++) {
    S[i] = (S[i - 1] + DP[i]) % MOD;
  }
}
int main() {
  scanf("%d%d", &t, &k);
  eval();
  while (t--) {
    scanf("%d%d", &a, &b);
    if (a == 1) {
      printf("%d\n", S[b] - 1);
    } else {
      printf("%d\n", (S[b] - S[a - 1] + MOD) % MOD);
    }
  }
  return 0;
}
