#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
long long f[100010];
int dp[100010][2], s[100010];
int main() {
  int T, i, j, ca = 0, m, k, n;
  while (~scanf("%d%d", &T, &k)) {
    dp[0][0] = 1;
    dp[0][1] = 1;
    long long s1 = 1;
    s[0] = 1;
    for (i = 1; i < 100010; i++) {
      dp[i][1] = s1;
      if (i >= k) dp[i][0] = s[i % k];
      (s1 += dp[i][0]) %= 1000000007;
      (s[i % k] += dp[i][1]) %= 1000000007;
      f[i] = f[i - 1];
      (f[i] += dp[i][1] + dp[i][0]) %= 1000000007;
    }
    while (T--) {
      scanf("%d%d", &i, &j);
      int ans = (f[j] - f[i - 1]) % 1000000007;
      if (ans < 0) ans += 1000000007;
      printf("%d\n", ans);
    }
  }
  return 0;
}
