#include <bits/stdc++.h>
using namespace std;
int parent[100010];
int Rank[100010];
int cnt;
int st[100010];
int st_cnt = 0;
void rollback(int id) {
  if (id < 0)
    Rank[-id - 1]--;
  else {
    parent[id] = id;
    cnt++;
  }
}
int find(int cur) {
  if (parent[cur] == cur) return cur;
  return find(parent[cur]);
}
void Union(int x, int y, bool revert = false) {
  int xroot = find(x);
  int yroot = find(y);
  if (xroot == yroot) return;
  cnt--;
  if (Rank[xroot] < Rank[yroot]) swap(xroot, yroot);
  if (revert) st[st_cnt++] = yroot;
  parent[yroot] = xroot;
  if (Rank[yroot] == Rank[xroot]) {
    Rank[xroot]++;
    if (revert) st[st_cnt++] = -xroot - 1;
  }
}
void init(int n) {
  st_cnt = 0;
  cnt = n;
  for (int i = 0; i <= n; ++i) {
    Rank[i] = 0;
    parent[i] = i;
  }
}
int x[100010], y[100010], Out[100010];
vector<int> List[600][600];
vector<int> befor[100010], after[100010];
int main() {
  int n, k, m, q, i, j;
  scanf("%d", &n);
  scanf("%d", &k);
  scanf("%d", &m);
  while (m--) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    --x;
    --y;
    if (x < y) {
      after[x].push_back(y);
      befor[y].push_back(x);
    } else {
      after[y].push_back(x);
      befor[x].push_back(y);
    }
  }
  init(n);
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &x[i]);
    scanf("%d", &y[i]);
    --x[i];
    --y[i];
    if (x[i] >= n) {
      Out[i] = 0;
      continue;
    }
    if (y[i] >= n) y[i] = n - 1;
    int sb = x[i] / 500;
    if (sb * 500 != x[i]) sb++;
    int eb = y[i] / 500;
    if ((eb + 1) * 500 != y[i] + 1) eb--;
    if (eb < sb) {
      for (j = x[i]; j <= y[i]; j++)
        for (auto z : befor[j])
          if (z >= x[i]) Union(j, z, true);
      Out[i] = cnt;
      while (st_cnt) {
        rollback(st[--st_cnt]);
      }
    } else
      List[sb][eb].push_back(i);
  }
  for (i = 0; i * 500 < n; i++) {
    init(n);
    for (j = i; (j + 1) * 500 <= n; j++) {
      for (int k = j * 500; k < (j + 1) * 500; k++)
        for (auto x : befor[k])
          if (x >= i * 500) Union(k, x);
      for (int k = 0; k < List[i][j].size(); k++) {
        for (int l = x[List[i][j][k]]; l < i * 500; l++)
          for (auto x : after[l])
            if (x < (j + 1) * 500) Union(l, x, true);
        for (int l = (j + 1) * 500; l <= y[List[i][j][k]]; l++)
          for (auto z : befor[l])
            if (z >= x[List[i][j][k]]) Union(l, z, true);
        Out[List[i][j][k]] = cnt;
        while (st_cnt) {
          rollback(st[--st_cnt]);
        }
      }
    }
  }
  for (i = 0; i < q; i++) printf("%d\n", Out[i] - (n - (y[i] - x[i] + 1)));
}
