#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
long long int n, k;
long long int tam;
long long int aa[1000100], bb[1000100];
long long int tree[1000100 * 2];
void build(int node = 1, int start = 1, int end = 100000) {
  if (start == end)
    tree[node] = aa[start];
  else {
    int mid = (start + end) >> 1;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node] = tree[2 * node] + tree[2 * node + 1];
  }
}
long long int query(int l, int r, int node = 1, int start = 1,
                    int end = 100000) {
  if (r < start or end < l) return 0;
  if (l <= start and end <= r) return tree[node];
  int mid = (start + end) >> 1;
  long long int p1 = query(l, r, 2 * node, start, mid);
  long long int p2 = query(l, r, 2 * node + 1, mid + 1, end);
  return (p1 + p2) % 1000000007;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) aa[i] = 1;
  aa[k] = 2;
  for (int i = k + 1; i <= 100001; i++)
    aa[i] = (aa[i - 1] + aa[i - k]) % 1000000007;
  build();
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    cout << query(a, b) % 1000000007 << endl;
  }
  return 0;
}
