#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int D[N], n, l, r, rt, m, k, ST[N], t, q;
vector<int> adj[N];
void add(int ind) {
  for (; ind < N; ind += ind & -ind) D[ind]++;
}
int get(int ind) { return (!ind ? 0 : D[ind] + get(ind -= ind & -ind)); }
void DFS(int u) {
  ST[u] = ++t;
  for (auto x : adj[u])
    if (!ST[x]) DFS(x);
}
bitset<N> B;
bool C(int u) {
  if (B[u]) return (0);
  for (auto x : adj[u])
    if (x >= l && x <= r && ST[x] < ST[u]) return (0);
  return (1);
}
int main() {
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < m; i++)
    scanf("%d %d", &l, &r), adj[l].push_back(r), adj[r].push_back(l);
  for (int i = 1; i <= n; i++)
    if (!ST[i]) B[i] = 1, DFS(i), add(i);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &l, &r);
    rt = get(r) - (l != 1 ? get(l - 1) : 0);
    for (int j = l; j <= min(l + k, r); j++) rt += C(j);
    for (int j = max(l + k + 1, r - k); j <= r; j++) rt += C(j);
    printf("%d\n", rt);
  }
}
