#include <bits/stdc++.h>
using namespace std;
const int M = 500005;
int n, m, q;
struct Edge {
  Edge() {}
  Edge(int u_, int v_) : u(u_), v(v_) {}
  int u, v;
  bool operator<(const Edge &a) const {
    if (v != a.v) return v < a.v;
    return u > a.u;
  }
} edge[M << 1];
int fa[M];
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
struct BIT {
  int C[M];
  void init() { memset(C, 0, n + 1 << 2); }
  void update(int x, int f) {
    for (; x; x -= x & -x) C[x] += f;
  }
  int query(int x) {
    int res = 0;
    for (; x <= n; x += x & -x) res += C[x];
    return res;
  }
} bit;
struct LCT {
  static const int N = M * 3;
  int fa[N], c[N][2], v[N], mn[N];
  char rev[N];
  void init() {
    for (int i = 0; i <= n + m; i++) {
      c[i][0] = c[i][1] = fa[i] = 0;
      v[i] = (1 << 30);
      mn[i] = i;
    }
  }
  bool isroot(int x) { return c[fa[x]][0] != x && c[fa[x]][1] != x; }
  int cmp(int x, int y) { return v[x] < v[y] ? x : y; }
  void up(int x) { mn[x] = cmp(cmp(mn[c[x][0]], mn[c[x][1]]), x); }
  int query(int x, int y) {
    makeroot(x);
    access(y);
    splay(y);
    return mn[y];
  }
  void rotate(int x) {
    int y = fa[x], z = fa[y], l, r;
    if (c[y][0] == x)
      l = 0;
    else
      l = 1;
    r = l ^ 1;
    if (!isroot(y)) {
      if (c[z][0] == y)
        c[z][0] = x;
      else
        c[z][1] = x;
    }
    fa[x] = z;
    fa[y] = x;
    fa[c[x][r]] = y;
    c[y][l] = c[x][r];
    c[x][r] = y;
    up(y);
  }
  int q[N];
  void down(int x) {
    if (rev[x]) {
      rev[c[x][0]] ^= 1;
      rev[c[x][1]] ^= 1;
      swap(c[x][0], c[x][1]);
      rev[x] = 0;
    }
  }
  void splay(int x) {
    int top = 0;
    q[++top] = x;
    for (int i = x; !isroot(i); i = fa[i]) q[++top] = fa[i];
    for (int i = top; i >= 1; i--) down(q[i]);
    while (!isroot(x)) {
      int y = fa[x], z = fa[y];
      if (!isroot(y)) {
        if (c[z][0] == y ^ c[y][0] == x)
          rotate(x);
        else
          rotate(y);
      }
      rotate(x);
    }
    up(x);
  }
  void makeroot(int x) {
    access(x);
    splay(x);
    rev[x] ^= 1;
  }
  void access(int x) {
    for (int t = 0; x; t = x, x = fa[x]) {
      splay(x);
      c[x][1] = t;
      up(x);
    }
  }
  void cut(int x, int y) {
    makeroot(x);
    access(y);
    splay(y);
    c[y][0] = fa[x] = 0;
  }
  void link(int x, int y) {
    makeroot(x);
    fa[x] = y;
  }
} lct;
int last[M], allc;
struct Query {
  int to, l, nxt;
} que[M];
void ins(int l, int r, int id) {
  que[allc].l = l;
  que[allc].to = id;
  que[allc].nxt = last[r];
  last[r] = allc++;
}
int ans[M];
void solve() {
  scanf("%d", &m);
  int tmp = 0;
  for (int u, v, i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    if (u == v) continue;
    if (u > v) swap(u, v);
    edge[++tmp] = Edge(u, v);
  }
  m = tmp;
  sort(edge + 1, edge + m + 1);
  for (int i = 1; i <= n; i++) fa[i] = i;
  bit.init();
  lct.init();
  memset(last, -1, n + 1 << 2);
  allc = 0;
  scanf("%d", &q);
  for (int l, r, i = 1; i <= q; i++) {
    scanf("%d%d", &l, &r);
    ins(l, r, i);
  }
  int pre = 1;
  for (int i = 1; i <= n; i++) {
    for (; pre <= m && edge[pre].v == i; pre++) {
      int u = edge[pre].u, v = edge[pre].v;
      if (get(u) == get(v)) {
        int id = lct.query(u, v);
        id -= n;
        if (edge[id].u >= u) continue;
        lct.cut(edge[id].u, id + n);
        lct.cut(edge[id].v, id + n);
        bit.update(edge[id].u, -1);
        lct.v[pre + n] = u;
        lct.link(u, pre + n);
        lct.link(v, pre + n);
        bit.update(u, 1);
      } else {
        lct.v[pre + n] = u;
        lct.link(u, pre + n);
        lct.link(v, pre + n);
        bit.update(u, 1);
        fa[get(u)] = get(v);
      }
    }
    for (int j = last[i]; j != -1; j = que[j].nxt) {
      int l = que[j].l, to = que[j].to;
      ans[to] = (i - l + 1) - bit.query(l);
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
int main() {
  while (~scanf("%d%d", &n, &m)) solve();
  return 0;
}
