#include <bits/stdc++.h>
using namespace std;
struct v {
  int ans, l, r;
  vector<int> s, f;
  v(int l_ = 0, int r_ = 0) {
    l = l_;
    r = r_;
    ans = 0;
  }
} it[(1 << 20)];
int n, k = 17, jk;
map<int, int> neigh[(1 << 20)];
void pf(vector<int> &a, int x) {
  reverse(a.begin(), a.end());
  a.push_back(x);
  reverse(a.begin(), a.end());
}
v mergeV(v a, v b) {
  v c;
  c.ans = a.ans + b.ans;
  for (int i = 0; i < a.f.size(); i++) {
    for (int j = 0; j < b.s.size(); j++) {
      if (a.f[i] == b.s[j]) {
        continue;
      }
      int u = a.r - a.f.size() + i, uV = a.f[i];
      int v = b.l + j, vV = b.s[j];
      if (neigh[u][v]) {
        for (int h = 0; h < a.s.size(); h++) {
          if (a.s[h] == uV) {
            a.s[h] = vV;
          }
        }
        for (int h = 0; h < a.f.size(); h++) {
          if (a.f[h] == uV) {
            a.f[h] = vV;
          }
        }
        for (int h = 0; h < b.s.size(); h++) {
          if (b.s[h] == uV) {
            b.s[h] = vV;
          }
        }
        for (int h = 0; h < b.s.size(); h++) {
          if (b.s[h] == uV) {
            a.f[h] = vV;
          }
        }
        c.ans--;
      }
    }
  }
  c.s = a.s;
  for (int i = 0; c.s.size() < jk && i < b.s.size(); i++) {
    c.s.push_back(b.s[i]);
  }
  c.f = b.f;
  for (int i = a.f.size() - 1; i >= 0 && c.f.size() < jk; i--) {
    pf(c.f, a.f[i]);
  }
  c.l = a.l;
  c.r = b.r;
  return c;
}
void printV(v ans) {
  cout << ans.l << "  " << ans.r << " \n";
  cout << ans.ans << " <--- \n";
  for (int i = 0; i < ans.s.size(); i++) {
    cout << ans.s[i] << " ";
  }
  cout << "\n";
  for (int i = 0; i < ans.f.size(); i++) {
    cout << ans.f[i] << " ";
  }
  cout << "\n";
}
v getSum(int l, int r, int ll = 0, int rr = (1 << k), int ind = 1) {
  if (l <= ll && rr <= r) {
    return it[ind];
  }
  if (rr <= l || r <= ll) {
    return v(ll, rr);
  }
  return mergeV(getSum(l, r, ll, (ll + rr) / 2, ind * 2),
                getSum(l, r, (ll + rr) / 2, rr, ind * 2 + 1));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> jk;
  for (int i = (1 << k); i < (1 << k + 1); i++) {
    it[i].l = i - (1 << k);
    it[i].r = i + 1 - (1 << k);
  }
  for (int i = 1; i <= n; i++) {
    it[i + (1 << k)].s.push_back(i);
    it[i + (1 << k)].f.push_back(i);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    neigh[a][b] = 1;
    neigh[b][a] = 1;
  }
  for (int i = (1 << k) - 1; i; i--) {
    it[i] = mergeV(it[i * 2], it[i * 2 + 1]);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    v ans = getSum(l, r + 1);
    cout << ans.ans + r - l + 1 << "\n";
  }
  return 0;
}
