#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int L = 21;
int n, len, m, q;
vector<int> e[maxn];
int c[maxn << 2], fa[L][maxn], bits[maxn << 2], used[L][maxn];
set<int> s1, s2;
int tmp[maxn];
inline int read() {
  int x = 0, ch;
  while (ch = getchar(), !isdigit(ch))
    ;
  while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x;
}
inline int root(int k, int x) {
  return fa[k][x] == x ? x : fa[k][x] = root(k, fa[k][x]);
}
inline void merge(int k, int x, int y) {
  x = root(k, x);
  y = root(k, y);
  if (x != y) fa[k][x] = y;
}
inline void buildtree(int k, int l, int r) {
  if (l == r) {
    c[k] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  buildtree(k << 1, l, mid);
  buildtree(k << 1 | 1, mid + 1, r);
  for (int i = l; i <= r; i++)
    for (auto j : e[i])
      if (j >= l && j <= r) merge(bits[k], i, j);
  for (int i = l; i <= r; i++) used[bits[k]][root(bits[k], i)] = 1;
  for (int i = l; i <= r; i++) c[k] += used[bits[k]][i];
}
inline int root(int x) { return tmp[x] == x ? x : root(tmp[x]); }
inline void merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x != y) tmp[x] = y;
}
inline int find(int k, int l, int r, int L, int R) {
  if (l > R || r < L) return 0;
  if (L <= l && R >= r) return c[k];
  int mid = (l + r) >> 1;
  if (mid >= R) return find(k << 1, l, mid, L, R);
  if (mid < L) return find(k << 1 | 1, mid + 1, r, L, R);
  int ret = find(k << 1, l, mid, L, R) + find(k << 1 | 1, mid + 1, r, L, R),
      st = max(max(l, L), mid - 5), ed = min(min(r, R), mid + 5);
  s1.clear();
  for (int i = st; i <= ed; i++) s1.insert(root(bits[k] + 1, i));
  for (int i = st; i <= ed; i++) tmp[i] = i;
  for (int i = st + 1; i <= ed; i++)
    for (int j = st; j < i; j++)
      if (root(bits[k] + 1, i) == root(bits[k] + 1, j)) {
        tmp[i] = tmp[j];
        break;
      }
  for (int i = st; i <= ed; i++)
    for (auto j : e[i])
      if (j >= st && j <= ed) merge(i, j);
  s2.clear();
  for (int i = st; i <= ed; i++) s2.insert(root(i));
  return ret - (s1.size() - s2.size());
}
int main() {
  n = read();
  len = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    e[u].push_back(v);
    e[v].push_back(u);
  }
  bits[0] = -1;
  for (int i = 1; i < (maxn << 2); i++) bits[i] = 1 + bits[i >> 1];
  for (int i = 0; i < L; i++)
    for (int j = 1; j <= n; j++) fa[i][j] = j;
  buildtree(1, 1, n);
  q = read();
  while (q--) {
    int l = read(), r = read();
    if (l > n)
      printf("0\n");
    else
      printf("%d\n", find(1, 1, n, l, min(r, n)));
  }
  return 0;
}
