#include <bits/stdc++.h>
using namespace std;
const int maxn = 100011;
bool E[maxn][7];
int n, k;
void init() {
  int m;
  scanf("%d%d%d", &n, &k, &m);
  memset(E, 0, sizeof(E));
  for (int i = 1, a, b; i <= m; ++i) {
    scanf("%d%d", &a, &b);
    if (a > b) swap(a, b);
    E[a][b - a] = 1;
  }
}
int fa[31];
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
struct Tseg {
  struct node {
    int l, r, sum;
    int L[7], R[7];
    node operator+(node a) {
      node b;
      b.l = l;
      b.r = a.r;
      b.sum = sum + a.sum;
      for (int i = 1; i <= 30; ++i) fa[i] = i;
      for (int i = max(l, r - k + 1); i <= r; ++i)
        for (int j = a.l - i; j <= k && i + j <= a.r; ++j)
          if (E[i][j] && find(R[r - i + 1]) != find(a.L[i + j - a.l + 1] + 15))
            fa[find(R[r - i + 1])] = find(a.L[i + j - a.l + 1] + 15), --b.sum;
      memset(b.L, 255, sizeof(b.L));
      memset(b.R, 255, sizeof(b.R));
      for (int i = 1; i <= k && l + i - 1 <= r; ++i) b.L[i] = find(L[i]);
      for (int i = 1; a.l + i - 1 <= a.r && a.l + i - l <= k; ++i)
        b.L[a.l + i - l] = find(a.L[i] + 15);
      for (int i = 1; i <= k && a.r - i + 1 >= a.l; ++i)
        b.R[i] = find(a.R[i] + 15);
      for (int i = 1; r - i + 1 >= l && a.r - r + i <= k; ++i)
        b.R[a.r - r + i] = find(R[i]);
      static int BB[31];
      memset(BB, 0, sizeof(BB));
      for (int i = 1; i <= k; ++i)
        if (b.L[i] != -1) BB[b.L[i]] = 1;
      for (int i = 1; i <= k; ++i)
        if (b.R[i] != -1) BB[b.R[i]] = 1;
      for (int i = 2; i <= 30; ++i) BB[i] += BB[i - 1];
      for (int i = 1; i <= k; ++i)
        if (b.L[i] != -1) b.L[i] = BB[b.L[i]];
      for (int i = 1; i <= k; ++i)
        if (b.R[i] != -1) b.R[i] = BB[b.R[i]];
      return b;
    }
    void watch() {
      cout << "-------------------------" << endl;
      cout << l << ' ' << r << ' ' << sum << endl;
      for (int i = 1; i <= k; ++i) cout << L[i] << ' ';
      cout << endl;
      for (int i = 1; i <= k; ++i) cout << R[i] << ' ';
      cout << endl;
      cout << endl;
      cout << endl;
    }
  } e[maxn << 2];
  void clear() { build(1, 1, n); }
  void build(int p, int l, int r) {
    e[p].l = l;
    e[p].r = r;
    if (l == r) {
      memset(e[p].L, 255, sizeof(e[p].L));
      memset(e[p].R, 255, sizeof(e[p].R));
      e[p].sum = 1;
      e[p].L[1] = 1;
      e[p].R[1] = 1;
      return;
    }
    int mid = (l + r) >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
    e[p] = e[p << 1] + e[p << 1 | 1];
  }
  node Query(int p, int l, int r, int fir, int las) {
    if (l == fir && r == las) return e[p];
    int mid = (l + r) >> 1;
    if (las <= mid) return Query(p << 1, l, mid, fir, las);
    if (fir > mid) return Query(p << 1 | 1, mid + 1, r, fir, las);
    return Query(p << 1, l, mid, fir, mid) +
           Query(p << 1 | 1, mid + 1, r, mid + 1, las);
  }
  int Query(int l, int r) { return Query(1, 1, n, l, r).sum; }
} T;
void work() {
  T.clear();
  int Q;
  scanf("%d", &Q);
  for (int i = 1, l, r; i <= Q; ++i)
    scanf("%d%d", &l, &r), printf("%d\n", T.Query(l, r));
}
int main() {
  init();
  work();
  return 0;
}
