#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
struct node {
  int l;
  int r;
  int ans;
  int pre[6];
  int suf[6];
  node() {
    l = -1;
    r = -1;
    ans = 0;
    memset(pre, 0, sizeof pre);
    memset(suf, 0, sizeof suf);
  }
  void unit(int x) {
    l = x;
    r = x;
    ans = 0;
    memset(pre, 0, sizeof pre);
    memset(suf, 0, sizeof suf);
    pre[1] = 1;
    suf[1] = 1;
  }
};
int n, m, k, u, v, q, l, r, f[50], id[50];
bool edge[N][6];
node t[N];
int get(int x) { return x == f[x] ? f[x] : f[x] = get(f[x]); }
node operator+(node a, node b) {
  node c;
  int u = 0;
  int v = 0;
  for (int i = 1; i <= 5; i++) {
    u = max(u, a.pre[i]);
    u = max(u, a.suf[i]);
  }
  for (int i = 1; i <= 5; i++) {
    v = max(v, b.pre[i]);
    v = max(v, b.suf[i]);
  }
  int s = u + v;
  for (int i = 1; i <= 5; i++) {
    if (b.pre[i] != 0) {
      b.pre[i] += u;
    }
    if (b.suf[i] != 0) {
      b.suf[i] += u;
    }
  }
  for (int i = 1; i <= s; i++) {
    f[i] = i;
    id[i] = 0;
  }
  int ans = a.ans + b.ans;
  for (int i = 1; i <= min(5, a.r - a.l + 1); i++) {
    if (a.suf[i] == 0) {
      continue;
    }
    int p = a.r - i + 1;
    for (int j = 1; j <= k; j++) {
      if (p + j < b.l || p + j > b.r) {
        continue;
      }
      if (edge[p][j] && get(a.suf[i]) != get(b.pre[p + j - b.l + 1]) != 0) {
        f[get(a.suf[i])] = get(b.pre[p + j - b.l + 1]);
        ans++;
      }
    }
  }
  for (int i = 1; i <= 5; i++) {
    if (a.pre[i] != 0) {
      c.pre[i] = a.pre[i];
    } else if (1 <= i - (a.r - a.l + 1) && i - (a.r - a.l + 1) <= 5) {
      c.pre[i] = b.pre[i - (a.r - a.l + 1)];
    } else {
      c.pre[i] = 0;
    }
  }
  for (int i = 1; i <= 5; i++) {
    if (b.suf[i] != 0) {
      c.suf[i] = b.suf[i];
    } else if (1 <= i - (b.r - b.l + 1) && i - (b.r - b.l + 1) <= 5) {
      c.suf[i] = a.suf[i - (b.r - b.l + 1)];
    } else {
      c.suf[i] = 0;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= 5; i++) {
    if (c.pre[i] == 0) {
      continue;
    }
    c.pre[i] = get(c.pre[i]);
    if (id[c.pre[i]] == 0) {
      id[c.pre[i]] = ++cnt;
    }
    c.pre[i] = id[c.pre[i]];
  }
  for (int i = 1; i <= 5; i++) {
    if (c.suf[i] == 0) {
      continue;
    }
    c.suf[i] = get(c.suf[i]);
    if (id[c.suf[i]] == 0) {
      id[c.suf[i]] = ++cnt;
    }
    c.suf[i] = id[c.suf[i]];
  }
  c.l = (a.l != -1) ? a.l : b.l;
  c.r = (b.r != -1) ? b.r : a.r;
  c.ans = ans;
  return c;
}
void build(int root, int rl, int rr) {
  if (rl == rr) {
    t[root].unit(rl);
  } else {
    int mid = (rl + rr) / 2;
    build(root * 2 + 1, rl, mid);
    build(root * 2 + 2, mid + 1, rr);
    t[root] = t[root * 2 + 1] + t[root * 2 + 2];
  }
}
node ask(int root, int rl, int rr, int l, int r) {
  if (l > r) {
    return node();
  }
  if (l == rl && r == rr) {
    return t[root];
  }
  int mid = (rl + rr) / 2;
  return ask(root * 2 + 1, rl, mid, l, min(r, mid)) +
         ask(root * 2 + 2, mid + 1, rr, max(l, mid + 1), r);
}
int main() {
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    u--;
    v--;
    if (u > v) {
      swap(u, v);
    }
    edge[u][v - u] = true;
  }
  build(0, 0, n - 1);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &l, &r);
    l--;
    r--;
    r = min(r, n - 1);
    if (l > r) {
      puts("0");
    } else {
      printf("%d\n", r - l + 1 - ask(0, 0, n - 1, l, r).ans);
    }
  }
  return 0;
}
