#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, K, a, b;
  scanf(" %d %d %d", &N, &M, &K);
  vector<vector<int> > adjL(N);
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    adjL[--a].push_back(--b);
  }
  vector<bool> bs(N, false);
  for (int i = 0; i < N; i++) {
    if (adjL[i].size() > 2) {
      printf("0\n");
      return 0;
    };
    for (auto it = adjL[i].begin(); it != adjL[i].end(); it++) {
      if (*it > i + 1 && *it != i + K + 1) {
        printf("0\n");
        return 0;
      };
      if (*it == i + K + 1) bs[i] = true;
    }
  }
  vector<int> pow(K + 1, 1);
  for (int i = 1; i <= K; i++) {
    pow[i] = (pow[i - 1] * 2) % 1000000007;
    if (pow[i] < 0) pow[i] += 1000000007;
  }
  int ans = 0, n = 0;
  a = b = -1;
  for (int i = 0; i < N; i++)
    if (bs[i]) {
      n++;
      if (a == -1)
        a = i;
      else
        b = i;
    }
  if (b > a + K) {
    printf("0\n");
    return 0;
  };
  if (a == -1) {
    ans = 1;
    for (int i = 0; i < N - 1 - K; i++) {
      ans = (ans + pow[min(K, N - 2 - K - i)]) % 1000000007;
      if (ans < 0) ans += 1000000007;
    }
    printf("%d\n", ans);
    return 0;
  }
  for (int i = max(0, b - K); i < min(N - 1 - K, a); i++) {
    ans = (ans + pow[min(K, N - 2 - K - i) - n]) % 1000000007;
    if (ans < 0) ans += 1000000007;
  }
  ans = (ans + pow[min(K, N - 2 - K - a) - n + 1]) % 1000000007;
  if (ans < 0) ans += 1000000007;
  printf("%d\n", ans);
  return 0;
}
