#include <bits/stdc++.h>
using namespace std;
bool vis[100005][10];
int n, k, m, q, rt[100005], nd[4 * 100005][2][6], val[4 * 100005];
int find_rt(int x) {
  if (rt[x] == x) return x;
  rt[x] = find_rt(rt[x]);
  return rt[x];
}
void make(int l, int r, int seg) {
  int i, j;
  if (l == r) {
    val[seg] = 1;
    nd[seg][0][1] = nd[seg][1][1] = l;
    return;
  }
  int mid = (l + r) / 2;
  int x, y;
  make(l, mid, seg * 2);
  make(mid + 1, r, seg * 2 + 1);
  val[seg] = val[seg * 2] + val[seg * 2 + 1];
  for (i = 0; i < k; i++) {
    if (mid - i < l) break;
    for (j = i + 1; j <= k; j++) {
      if (mid - i + j > r) break;
      if (vis[mid - i][j]) {
        x = find_rt(mid - i);
        y = find_rt(mid - i + j);
        if (x != y) {
          val[seg]--;
          rt[x] = y;
        }
      }
    }
  }
  for (i = 0; i < k; i++) {
    if (l + i <= r) nd[seg][0][i + 1] = find_rt(l + i);
    if (r - i >= l) nd[seg][1][i + 1] = find_rt(r - i);
  }
  return;
}
int query(int L, int R, int l, int r, int seg) {
  if (l <= L && R <= r) {
    for (int i = 0; i < k; i++) {
      if (i + L <= R) {
        rt[i + L] = nd[seg][0][i + 1];
        rt[nd[seg][0][i + 1]] = nd[seg][0][i + 1];
      }
      if (R - i >= L) {
        rt[R - i] = nd[seg][1][i + 1];
        rt[nd[seg][1][i + 1]] = nd[seg][1][i + 1];
      }
    }
    return val[seg];
  }
  int mid = (L + R) / 2;
  if (mid >= r)
    return query(L, mid, l, r, seg * 2);
  else if (mid + 1 <= l)
    return query(mid + 1, R, l, r, seg * 2 + 1);
  else {
    int c = 0, i, s, t, x, y, j;
    s = query(L, mid, l, r, seg * 2);
    t = query(mid + 1, R, l, r, seg * 2 + 1);
    for (i = 0; i < k; i++) {
      if (mid - i < max(L, l)) break;
      for (int j = i + 1; j <= k; j++) {
        if (mid - i + j > min(R, r)) break;
        if (vis[mid - i][j]) {
          x = find_rt(mid - i);
          y = find_rt(mid - i + j);
          if (x != y) {
            c++;
            rt[x] = y;
          }
        }
      }
    }
    return s + t - c;
  }
}
int main() {
  int i, j, a, b, aaa;
  scanf("%d %d", &n, &k);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &a, &b);
    if (a > b) swap(a, b);
    vis[a][b - a] = 1;
  }
  for (i = 1; i <= n; i++) rt[i] = i;
  make(1, n, 1);
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &a, &b);
    printf("%d\n", query(1, n, a, b, 1));
  }
}
