#include <bits/stdc++.h>
using namespace std;
long long arr[100010];
long long dis[100010];
int main() {
  long long total, cnt;
  cin >> total >> cnt;
  for (long long i = 1; i < cnt; i++) {
    dis[i] = 1;
    arr[i] = arr[i - 1] % 1000000007;
    arr[i]++;
  }
  dis[cnt] = 2;
  arr[cnt] = arr[cnt - 1];
  arr[cnt] += 2;
  arr[cnt] %= 1000000007;
  for (long long i = cnt + 1; i <= 100000; i++) {
    dis[i] = dis[i - cnt] + dis[i - 1];
    arr[i] = arr[i - 1];
    arr[i] += dis[i];
    arr[i] %= 1000000007;
    dis[i] %= 1000000007;
  }
  for (long long i = 1; i <= total; i++) {
    long long l, r;
    cin >> l >> r;
    cout << (arr[r] - arr[l - 1] + 1000000007) % 1000000007 << endl;
  }
}
