#include <bits/stdc++.h>
using namespace std;
struct node {
  int y, nex;
} a[1100000];
struct node2 {
  int fl[5], fr[5], cnt, siz, l, r;
  node2() {
    memset(fl, 0, sizeof(fl));
    memset(fr, 0, sizeof(fr));
    cnt = siz = l = r = 0;
  }
};
struct node1 {
  int l, r, lc, rc;
  node2 t;
} lt[2 * 110000];
int fir[110000], len, n, m, q, tl, fa[50], b[50];
void ins(int x, int y) {
  a[++len].y = y;
  a[len].nex = fir[x];
  fir[x] = len;
}
void init() {
  scanf("%d%d", &n, &m);
  int t;
  scanf("%d", &t);
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    ins(x, y);
    ins(y, x);
  }
}
int find(int x) {
  if (fa[x] != x) fa[x] = find(fa[x]);
  return fa[x];
}
node2 merge(node2 t1, node2 t2) {
  node2 t;
  t.l = t1.l;
  t.r = t2.r;
  int len = t.r - t.l + 1, l = t.l, r = t.r;
  if (len <= 2 * m) {
    for (int i = 1; i <= len; i++) fa[i] = i;
    for (int x = l; x <= r; x++)
      for (int k = fir[x]; k; k = a[k].nex) {
        int y = a[k].y;
        if (l <= y && y <= r) {
          int fx = find(x - l + 1), fy = find(y - l + 1);
          if (fx != fy) fa[fx] = fy;
        }
      }
    for (int i = 1; i <= len; i++) b[i] = 0;
    t.cnt = 0;
    for (int i = 1; i <= len; i++) {
      fa[i] = find(i);
      if (b[fa[i]] == 0) {
        b[fa[i]] = 1;
        t.cnt++;
      }
    }
    int num = 0;
    for (int i = 1; i <= len; i++)
      if (b[i]) b[i] = ++num;
    t.siz = num;
    for (int i = 0; i < m; i++)
      if (l + i <= r) t.fl[i] = b[fa[i + 1]], t.fr[i] = b[fa[len - i]];
  } else {
    t.cnt = t1.cnt + t2.cnt - t1.siz - t2.siz;
    int siz = t1.siz + t2.siz;
    for (int i = 0; i < m; i++) {
      if (t2.fl[i]) t2.fl[i] += t1.siz;
      if (t2.fr[i]) t2.fr[i] += t1.siz;
    }
    for (int i = 1; i <= siz; i++) fa[i] = i;
    for (int i = 0; i < m; i++) {
      int x = t1.r - i;
      if (x >= t1.l) {
        for (int k = fir[x]; k; k = a[k].nex) {
          int y = a[k].y;
          if (t2.l <= y && y < min(t2.l + m, t2.r + 1)) {
            int fx = find(t1.fr[i]), fy = find(t2.fl[y - t2.l]);
            if (fx != fy) fa[fx] = fy;
          }
        }
      }
      x = t2.l + i;
      if (x <= t2.r) {
        for (int k = fir[x]; k; k = a[k].nex) {
          int y = a[k].y;
          if (t1.r >= y && y > max(t1.r - m, t1.l - 1)) {
            int fx = find(t2.fl[i]), fy = find(t1.fr[t1.r - y]);
            if (fx != fy) fa[fx] = fy;
          }
        }
      }
    }
    for (int i = 1; i <= siz; i++)
      if (find(i) == i) t.cnt++;
    for (int i = 0; i < m; i++) {
      if (t1.fl[i] == 0) t1.fl[i] = t2.fl[i + t1.l - t2.l];
      if (t2.fr[i] == 0) t2.fr[i] = t1.fr[t1.r - (t2.r - i)];
    }
    for (int i = 1; i <= siz; i++) b[i] = 0;
    int num = 0;
    for (int i = 0; i < m; i++) b[fa[t1.fl[i]]] = b[fa[t2.fr[i]]] = 1;
    for (int i = 1; i <= siz; i++)
      if (b[i]) b[i] = ++num;
    for (int i = 0; i < m; i++)
      t.fl[i] = b[fa[t1.fl[i]]], t.fr[i] = b[fa[t2.fr[i]]];
    t.siz = num;
  }
  return t;
}
void bt(int l, int r) {
  int now = ++tl;
  lt[now].l = lt[now].t.l = l;
  lt[now].r = lt[now].t.r = r;
  if (l < r) {
    int mid = (l + r) / 2;
    int lc = lt[now].lc = tl + 1;
    bt(l, mid);
    int rc = lt[now].rc = tl + 1;
    bt(mid + 1, r);
    lt[now].t = merge(lt[lc].t, lt[rc].t);
  } else
    lt[now].t.cnt = lt[now].t.siz = lt[now].t.fl[0] = lt[now].t.fr[0] = 1;
}
node2 query(int now, int l, int r) {
  int lc = lt[now].lc, rc = lt[now].rc, mid = (lt[now].l + lt[now].r) / 2;
  if (lt[now].l == l && lt[now].r == r) return lt[now].t;
  if (mid >= r)
    return query(lc, l, r);
  else if (l > mid)
    return query(rc, l, r);
  else {
    node2 t, t1, t2;
    t1 = query(lc, l, mid);
    t2 = query(rc, mid + 1, r);
    t = merge(t1, t2);
    return t;
  }
}
void solve() {
  bt(1, n);
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    node2 ans = query(1, l, r);
    printf("%d\n", ans.cnt);
  }
}
int main() {
  init();
  solve();
  return 0;
}
