#include <bits/stdc++.h>
using namespace std;
int n, k, m, q, a, b, c = 0;
int bit[100005], r[100005];
bool u[100005];
vector<int> v[100005];
void bitadd(int P) {
  for (; P <= n; P += P & -P) bit[P]++;
}
int bitsum(int P) {
  int C = 0;
  for (; P > 0; P -= P & -P) C += bit[P];
  return C;
}
void dfs(int N) {
  if (r[N] > 0) return;
  r[N] = ++c;
  for (int l = 0; l < v[N].size(); ++l) dfs(v[N][l]);
}
int check(int N) {
  if (u[N]) return 0;
  bool B = 1;
  for (int l = 0; l < v[N].size(); ++l) {
    if (v[N][l] < a || v[N][l] > b) continue;
    if (r[v[N][l]] < r[N]) B = 0;
  }
  return B;
}
int main() {
  scanf("%i%i%i", &n, &k, &m);
  for (int l = 0; l < m; ++l) {
    scanf("%i%i", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int l = 1; l <= n; ++l)
    if (r[l] == 0) {
      dfs(l);
      bitadd(l);
      u[l] = 1;
    }
  scanf("%i", &q);
  for (int l = 0; l < q; ++l) {
    scanf("%i%i", &a, &b);
    c = 0;
    for (int l2 = a; l2 <= min(b, a + k - 1); ++l2) c += check(l2);
    for (int l2 = max(a + k, b - k + 1); l2 <= b; ++l2) c += check(l2);
    c += bitsum(b) - bitsum(a - 1);
    printf("%i\n", c);
  }
  return 0;
}
