#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, q;
struct edge {
  int u, v;
  friend bool operator<(edge x, edge y) { return x.v < y.v; }
};
edge e[500100];
struct event {
  int id, l, r;
  friend bool operator<(event x, event y) { return x.r < y.r; }
};
event ev[100100];
int ans[100100];
int c[100100];
struct node_t {
  node_t *ch[2], *fa, *mm;
  int val;
  bool rev;
  bool isroot() { return !fa || (fa->ch[0] != this && fa->ch[1] != this); }
  int dir() { return (fa->ch[0] == this ? 0 : 1); }
  void setc(node_t *c, int d) {
    ch[d] = c;
    if (c) c->fa = this;
  }
  void reverse() {
    rev ^= 1;
    swap(ch[0], ch[1]);
  }
  void init(int v) {
    ch[0] = ch[1] = fa = 0;
    rev = 0;
    val = v;
    mm = this;
  }
  void update() {
    mm = this;
    if (ch[0] && ch[0]->mm->val < mm->val) mm = ch[0]->mm;
    if (ch[1] && ch[1]->mm->val < mm->val) mm = ch[1]->mm;
  }
  void sink() {
    if (rev) {
      if (ch[0]) ch[0]->reverse();
      if (ch[1]) ch[1]->reverse();
      rev = 0;
    }
  }
  void rot() {
    node_t *p = fa;
    int d = dir();
    if (p->isroot())
      fa = p->fa;
    else
      p->fa->setc(this, p->dir());
    p->setc(ch[d ^ 1], d), setc(p, d ^ 1);
    p->update(), update();
  }
  void sinkdown() {
    if (!isroot()) fa->sinkdown();
    sink();
  }
  void splay() {
    sinkdown();
    for (; !isroot(); rot()) {
      if (!fa->isroot()) {
        if (dir() == fa->dir())
          fa->rot();
        else
          rot();
      }
    }
  }
  node_t *expose() {
    node_t *u = 0, *t = this;
    for (; t; u = t, t = t->fa) {
      t->splay();
      t->ch[1] = u;
      t->update();
    }
    return u;
  }
  node_t *root() {
    node_t *t = expose();
    while (t->sink(), t->ch[0]) t = t->ch[0];
    return t;
  }
  void setroot() { expose()->reverse(); }
  void link(node_t *p) {
    setroot();
    expose()->fa = p;
  }
  void cut(node_t *p) {
    p->setroot();
    expose();
    splay();
    ch[0] = ch[0]->fa = 0;
    update();
  }
  node_t *query(node_t *t) {
    setroot();
    return t->expose()->mm;
  }
};
node_t node[100100 + 500100];
void add(int i, int x) {
  for (; i <= n; i += i & (-i)) c[i] += x;
}
int sum(int i) {
  int s = 0;
  for (; i; i -= i & (-i)) s += c[i];
  return s;
}
int lll[100100], rrr[100100];
void init() {
  int kkk;
  cin >> n >> kkk;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> e[i].u >> e[i].v;
    if (e[i].u > e[i].v) swap(e[i].u, e[i].v);
  }
  sort(e + 1, e + 1 + m);
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> ev[i].l >> ev[i].r;
    ev[i].id = i;
    lll[i] = ev[i].l;
    rrr[i] = ev[i].r;
  }
  sort(ev + 1, ev + 1 + q);
  for (int i = 0; i <= n; i++) c[i] = 0;
  for (int i = 1; i <= n; i++) node[i].init(INT_MAX);
  for (int i = 1; i <= m; i++) node[i + n].init(e[i].u);
}
void solve() {
  for (int i = 1, j = 1; i <= q; i++) {
    while (j <= m && e[j].v <= ev[i].r) {
      if (e[j].u == e[j].v) {
        j++;
        continue;
      }
      if (node[e[j].u].root() == node[e[j].v].root()) {
        int k = node[e[j].u].query(&node[e[j].v]) - node - n;
        node[k + n].cut(&node[e[k].u]);
        node[k + n].cut(&node[e[k].v]);
        add(e[k].u, -1);
      }
      node[j + n].link(&node[e[j].u]);
      node[j + n].link(&node[e[j].v]);
      add(e[j].u, 1);
      j++;
    }
    ans[ev[i].id] = n - (sum(n) - sum(ev[i].l - 1));
  }
  for (int i = 1; i <= q; i++)
    cout << ans[i] - (n - (rrr[i] - lll[i] + 1)) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  init();
  solve();
  return 0;
}
