#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
long long dp[100005], s[100005];
int main() {
  scanf("%d%d", &n, &m);
  dp[0] = 1;
  for (int i = 1; i <= 100000; i++)
    if (i >= m)
      dp[i] = (dp[i - m] + dp[i - 1]) % 1000000007;
    else
      dp[i] = dp[i - 1] % 1000000007;
  s[0] = 1;
  for (int i = 1; i <= 100000; i++) s[i] = (s[i - 1] + dp[i]) % 1000000007;
  while (scanf("%d%d", &x, &y) == 2) {
    long long ans = s[y] - s[x - 1];
    ans = (ans % 1000000007 + 1000000007) % 1000000007;
    printf("%lld\n", ans);
  }
  return 0;
}
