#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void ckmax(T& x, T y) {
  x = (y > x ? y : x);
}
template <typename T>
inline void ckmin(T& x, T y) {
  x = (y < x ? y : x);
}
namespace Fread {
const int SIZE = 1 << 21;
char buf[SIZE], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, SIZE, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
}  // namespace Fread
namespace Fwrite {
const int SIZE = 1 << 21;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush() {
  fwrite(buf, 1, S - buf, stdout);
  S = buf;
}
inline void putchar(char c) {
  *S++ = c;
  if (S == T) flush();
}
struct NTR {
  ~NTR() { flush(); }
} ztr;
}  // namespace Fwrite
namespace Fastio {
struct Reader {
  template <typename T>
  Reader& operator>>(T& x) {
    char c = Fread ::getchar();
    T f = 1;
    while (c < '0' || c > '9') {
      if (c == '-') f = -1;
      c = Fread ::getchar();
    }
    x = 0;
    while (c >= '0' && c <= '9') {
      x = x * 10 + (c - '0');
      c = Fread ::getchar();
    }
    x *= f;
    return *this;
  }
  Reader& operator>>(char& c) {
    c = Fread ::getchar();
    while (c == '\n' || c == ' ') c = Fread ::getchar();
    return *this;
  }
  Reader& operator>>(char* str) {
    int len = 0;
    char c = Fread ::getchar();
    while (c == '\n' || c == ' ') c = Fread ::getchar();
    while (c != '\n' && c != ' ') {
      str[len++] = c;
      c = Fread ::getchar();
    }
    str[len] = '\0';
    return *this;
  }
  Reader() {}
} cin;
const char endl = '\n';
struct Writer {
  template <typename T>
  Writer& operator<<(T x) {
    if (x == 0) {
      Fwrite ::putchar('0');
      return *this;
    }
    if (x < 0) {
      Fwrite ::putchar('-');
      x = -x;
    }
    static int sta[45];
    int top = 0;
    while (x) {
      sta[++top] = x % 10;
      x /= 10;
    }
    while (top) {
      Fwrite ::putchar(sta[top] + '0');
      --top;
    }
    return *this;
  }
  Writer& operator<<(char c) {
    Fwrite ::putchar(c);
    return *this;
  }
  Writer& operator<<(char* str) {
    int cur = 0;
    while (str[cur]) Fwrite ::putchar(str[cur++]);
    return *this;
  }
  Writer& operator<<(const char* str) {
    int cur = 0;
    while (str[cur]) Fwrite ::putchar(str[cur++]);
    return *this;
  }
  Writer() {}
} cout;
}  // namespace Fastio
const int MAXN = 1e5;
const int BLOCK_SIZE = 400;
const int BLOCK_NUM = MAXN / BLOCK_SIZE + 5;
template <const int SIZE>
struct DSU {
  int cnt_cc;
  int fa[SIZE + 5], sz[SIZE + 5];
  int get_fa(int u) { return (u == fa[u]) ? u : (fa[u] = get_fa(fa[u])); }
  bool unite(int u, int v) {
    u = get_fa(u);
    v = get_fa(v);
    if (u != v) {
      if (sz[u] > sz[v]) {
        swap(u, v);
      }
      fa[u] = v;
      sz[v] += sz[u];
      --cnt_cc;
      return true;
    }
    return false;
  }
  DSU() {}
};
int n, K, m;
int bel[MAXN + 5], cnt_block;
vector<int> G[MAXN + 5];
int id[MAXN + 5];
DSU<BLOCK_SIZE> dsu2, dsu3, dsu4;
struct Block {
  int st, ed;
  DSU<BLOCK_SIZE> dsu1;
  vector<pair<int, int> > e_pre;
  void add_edge_inside(int u, int v) { dsu1.unite(u - st + 1, v - st + 1); }
  void add_edge_pre(int u, int v) { e_pre.push_back(make_pair(u, v)); }
  void init(int _st, int _ed) {
    st = _st;
    ed = _ed;
    for (int i = st; i <= ed; ++i) {
      dsu1.fa[i - st + 1] = i - st + 1;
      dsu1.sz[i - st + 1] = 1;
    }
    dsu1.cnt_cc = ed - st + 1;
  }
  int get_ans_inside(DSU<BLOCK_SIZE>& dsu, int l, int r) {
    for (int i = l; i <= r; ++i) {
      dsu.fa[i - st + 1] = i - st + 1;
      dsu.sz[i - st + 1] = 1;
    }
    dsu.cnt_cc = r - l + 1;
    for (int i = l; i <= r; ++i) {
      for (int j = ((int)(G[i]).size()) - 1; j >= 0; --j) {
        int v = G[i][j];
        if (v < l) break;
        dsu.unite(i - st + 1, v - st + 1);
      }
    }
    return dsu.cnt_cc;
  }
  int get_ans_whole_block(DSU<BLOCK_SIZE>& Pre, int l) {
    int res = dsu1.cnt_cc;
    int cnt = 0;
    for (int i = max(l, st - 5); i <= min(st + 4, ed); ++i) {
      id[i] = ++cnt;
    }
    for (int i = 1; i <= cnt; ++i) {
      dsu2.fa[i] = i;
      dsu2.sz[i] = 1;
    }
    for (int i = max(l, st - 5) + 1; i < st; ++i) {
      for (int j = max(l, st - 5); j < i; ++j) {
        if (Pre.get_fa(i - (st - BLOCK_SIZE) + 1) ==
            Pre.get_fa(j - (st - BLOCK_SIZE) + 1)) {
          dsu2.unite(id[i], id[j]);
        }
      }
    }
    for (int i = st + 1; i <= min(st + 4, ed); ++i) {
      for (int j = st; j < i; ++j) {
        if (dsu1.get_fa(i - st + 1) == dsu1.get_fa(j - st + 1)) {
          dsu2.unite(id[i], id[j]);
        }
      }
    }
    for (int i = 0; i < ((int)(e_pre).size()); ++i) {
      if (e_pre[i].first >= l)
        res -= dsu2.unite(id[e_pre[i].first], id[e_pre[i].second]);
    }
    return res;
  }
  int get_ans_prefix(DSU<BLOCK_SIZE>& Pre, int l, int r) {
    int res = get_ans_inside(dsu4, st, r);
    int cnt = 0;
    for (int i = max(l, st - 5); i <= min(st + 4, r); ++i) {
      id[i] = ++cnt;
    }
    for (int i = 1; i <= cnt; ++i) {
      dsu2.fa[i] = i;
      dsu2.sz[i] = 1;
    }
    for (int i = max(l, st - 5) + 1; i < st; ++i) {
      for (int j = max(l, st - 5); j < i; ++j) {
        if (Pre.get_fa(i - (st - BLOCK_SIZE) + 1) ==
            Pre.get_fa(j - (st - BLOCK_SIZE) + 1)) {
          dsu2.unite(id[i], id[j]);
        }
      }
    }
    for (int i = st + 1; i <= min(st + 4, r); ++i) {
      for (int j = st; j < i; ++j) {
        if (dsu4.get_fa(i - st + 1) == dsu4.get_fa(j - st + 1)) {
          dsu2.unite(id[i], id[j]);
        }
      }
    }
    for (int i = 0; i < ((int)(e_pre).size()); ++i) {
      if (e_pre[i].first >= l && e_pre[i].second <= r)
        res -= dsu2.unite(id[e_pre[i].first], id[e_pre[i].second]);
    }
    return res;
  }
  Block() {}
};
Block B[BLOCK_NUM + 5];
int main() {
  Fastio ::cin >> n >> K;
  for (int i = 1; i <= n; i += BLOCK_SIZE) {
    int j = min(i + BLOCK_SIZE - 1, n);
    ++cnt_block;
    for (int k = i; k <= j; ++k) {
      bel[k] = cnt_block;
    }
    B[cnt_block].init(i, j);
  }
  Fastio ::cin >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    Fastio ::cin >> u >> v;
    if (u > v) swap(u, v);
    G[v].push_back(u);
    if (bel[u] == bel[v]) {
      B[bel[u]].add_edge_inside(u, v);
    } else {
      assert(bel[u] == bel[v] - 1);
      B[bel[v]].add_edge_pre(u, v);
    }
  }
  for (int i = 1; i <= n; ++i) {
    assert(((int)(G[i]).size()) <= 5);
    sort(G[i].begin(), G[i].end());
  }
  int q;
  Fastio ::cin >> q;
  for (int tq = 1; tq <= q; ++tq) {
    int l, r;
    Fastio ::cin >> l >> r;
    int ans = 0;
    if (bel[l] == bel[r]) {
      ans = B[bel[l]].get_ans_inside(dsu3, l, r);
    } else {
      ans = B[bel[l]].get_ans_inside(dsu3, l, B[bel[l]].ed);
      for (int i = bel[l] + 1; i < bel[r]; ++i) {
        ans += B[i].get_ans_whole_block(
            ((i == bel[l] + 1) ? dsu3 : B[i - 1].dsu1), l);
      }
      ans += B[bel[r]].get_ans_prefix(
          ((bel[r] == bel[l] + 1) ? dsu3 : B[bel[r] - 1].dsu1), l, r);
    }
    Fastio ::cout << ans << Fastio ::endl;
  }
  return 0;
}
