#include <bits/stdc++.h>
using namespace std;
const int NN = 1e5 + 5;
int N, K, M;
vector<int> G[NN], T[NN];
int fa[NN];
int Get(int u) { return (u == fa[u]) ? u : (fa[u] = Get(fa[u])); }
void Mer(int u, int v) {
  u = Get(u);
  v = Get(v);
  if (u != v) fa[u] = v;
}
int Cal(int l, int r) {
  for (int i = l; i <= r; ++i) {
    fa[i] = i;
  }
  for (int i = l; i <= r; ++i) {
    for (int j = 0; j < G[i].size(); ++j) {
      int t = G[i][j];
      if (t >= l && t <= r) Mer(i, t);
    }
  }
  int cnt = 0;
  for (int i = l; i <= r; ++i)
    if (fa[i] == i) ++cnt;
  return cnt;
}
struct Edge {
  int u, v, w;
  Edge(int _u, int _v, int _w) : u(_u), v(_v), w(_w) {}
  Edge() : u(0), v(0), w(0) {}
  bool operator<(const Edge &d) const { return w < d.w; }
} edge[NN * 5];
int totE, deg[NN];
void AddE(int u, int v, int l) { edge[++totE] = Edge(u, v, l); }
int abs(int x) { return (x >= 0) ? x : (-x); }
int sum[NN];
int main() {
  scanf("%d%d%d", &N, &K, &M);
  for (int i = 1; i <= M; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
    AddE(u, v, abs(u - v));
  }
  sort(edge + 1, edge + totE + 1);
  for (int i = 1; i <= N; ++i) fa[i] = i;
  for (int i = 1; i <= totE; ++i) {
    int u = edge[i].u, v = edge[i].v;
    u = Get(u);
    v = Get(v);
    if (u != v) {
      fa[u] = v;
      ++deg[edge[i].v];
      ++deg[edge[i].u];
      T[edge[i].u].push_back(edge[i].v);
      T[edge[i].v].push_back(edge[i].u);
    }
  }
  sum[0] = 0;
  for (int i = 1; i <= N; ++i) sum[i] = sum[i - 1] + deg[i];
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (r - l + 1 <= 20) {
      printf("%d\n", Cal(l, r));
    } else {
      int del = 0;
      for (int i = l; i <= l + 4; ++i) {
        for (int j = 0; j < T[i].size(); ++j) {
          if (T[i][j] < l || T[i][j] > r) ++del;
        }
      }
      for (int i = r; i >= r - 4; --i) {
        for (int j = 0; j < T[i].size(); ++j) {
          if (T[i][j] < l || T[i][j] > r) ++del;
        }
      }
      printf("%d\n", (r - l + 1) - (sum[r] - sum[l - 1] - del) / 2);
    }
  }
  return 0;
}
