#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
struct Uds {
  vector<int> rep;
  void init(int n) {
    rep.resize(n);
    for (int i = 0; i < n; ++i) rep[i] = i;
  }
  int find(int x) {
    if (x == rep[x]) return x;
    return rep[x] = this->find(rep[x]);
  }
  void merge(int a, int b) {
    a = this->find(a);
    b = this->find(b);
    rep[a] = b;
  }
};
struct Val {
  int l, r;
  int cnt = -1000000;
  int data[10];
};
Val single(int i) {
  Val v;
  v.l = v.r = i;
  v.cnt = 1;
  for (int j = 0; j < 10; ++j) v.data[j] = 0;
  return v;
}
Val combine(Val a, Val b) {
  Uds uds;
  uds.init(20);
  for (int i = max(a.l, a.r - 4); i <= a.r; ++i) {
    for (int j : g[i]) {
      if (b.l <= j && j <= b.r) {
        uds.merge(a.data[5 + i + 4 - a.r], b.data[j - b.l] + 10);
      }
    }
  }
  set<int> used, needed;
  for (int i = 0; i < 10; ++i) {
    used.insert(a.data[i]);
    used.insert(b.data[i] + 10);
    needed.insert(uds.find(a.data[i]));
    needed.insert(uds.find(b.data[i] + 10));
  }
  Val c;
  c.l = a.l;
  c.r = b.r;
  c.cnt = a.cnt + b.cnt - (used.size() - needed.size());
  for (int i = 0; i < 5; ++i) {
    if (i <= a.r - a.l)
      c.data[i] = a.data[i];
    else
      c.data[i] = b.data[i - (a.r - a.l + 1)] + 10;
  }
  for (int i = 0; i < 5; ++i) {
    if (i <= b.r - b.l)
      c.data[9 - i] = b.data[9 - i] + 10;
    else
      c.data[9 - i] = a.data[9 - (i - (b.r - b.l + 1))];
  }
  map<int, int> mp;
  for (int i = 0; i < 10; ++i) {
    int x = uds.find(c.data[i]);
    if (!mp.count(x)) mp.insert({x, (int)mp.size()});
    c.data[i] = mp[x];
  }
  return c;
}
int n, k;
vector<Val> S;
void init() {
  for (int i = 0; i < n; ++i) {
    S[i + k] = single(i);
  }
  for (int i = k - 1; i > 0; --i) {
    if (S[2 * i].cnt < 0) continue;
    if (S[2 * i + 1].cnt < 0)
      S[i] = S[2 * i];
    else
      S[i] = combine(S[2 * i], S[2 * i + 1]);
  }
}
Val query(int l, int r, int a, int b, int i) {
  if (l <= a && b <= r) return S[i];
  if (b < l || r < a) return Val();
  int m = (a + b) / 2;
  Val x = query(l, r, a, m, 2 * i);
  Val y = query(l, r, m + 1, b, 2 * i + 1);
  if (y.cnt < 0) return x;
  if (x.cnt < 0) return y;
  return combine(x, y);
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int ___ignore;
  cin >> n >> ___ignore;
  g.resize(n);
  k = 1 << (int)ceil(log2(n));
  S.resize(2 * k);
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  init();
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    Val v = query(l, r, 1, k, 1);
    cout << v.cnt << "\n";
  }
}
