#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> adj[100005];
struct node {
  int num, suff[6], pre[6];
  node() {
    num = 0;
    for (int i = 0; i < 6; ++i) pre[i] = suff[i] = 0;
  }
};
node tree[400005];
int par[25], stay[25];
int parent(int x) {
  if (par[x] == x) return x;
  return par[x] = parent(par[x]);
}
node merg(node a, node b, int l, int r, int mid) {
  node ret;
  ret.num = a.num + b.num;
  int k1 = min(k, mid - l + 1), k2 = min(k, r - mid);
  set<int> s;
  for (int i = 0; i < k1; ++i) {
    s.insert(a.pre[i]);
    s.insert(a.suff[i]);
  }
  int x = s.size();
  for (int i = 0; i < k2; ++i) {
    s.insert(b.pre[i] + x);
    s.insert(b.suff[i] + x);
  }
  int x1 = s.size();
  for (int i = 1; i <= x1; ++i) par[i] = i;
  for (int i = 0; i < k1; ++i) {
    int u = mid - i;
    for (auto v : adj[u]) {
      if (v <= mid || v > r) continue;
      par[parent(b.pre[v - mid - 1] + x)] = parent(a.suff[i]);
    }
  }
  map<int, int> mp;
  for (int i = 0; i < k1; ++i) mp[parent(a.pre[i])];
  for (int i = 0; i < k2; ++i) mp[parent(b.suff[i] + x)];
  int need1 = min(k, k1 + k2) - k1, need2 = min(k, k1 + k2) - k2;
  for (int i = 0; i < need1; ++i) mp[parent(b.pre[i] + x)];
  for (int i = 0; i < need2; ++i) mp[parent(a.suff[i])];
  int cnt = 0;
  for (auto xx : mp) mp[xx.first] = ++cnt;
  for (int i = 0; i < k1; ++i) ret.pre[i] = mp[parent(a.pre[i])];
  for (int i = k1; i < min(k, k1 + k2); ++i)
    ret.pre[i] = mp[parent(b.pre[i - k1] + x)];
  for (int i = 0; i < k2; ++i) ret.suff[i] = mp[parent(b.suff[i] + x)];
  for (int i = k2; i < min(k, k1 + k2); ++i)
    ret.suff[i] = mp[parent(a.suff[i - k2])];
  for (int i = need1; i < k2; ++i) {
    if (!mp.count(parent(b.pre[i] + x))) {
      ++ret.num;
      mp[parent(b.pre[i] + x)];
    }
  }
  for (int i = need2; i < k1; ++i) {
    if (!mp.count(parent(a.suff[i]))) {
      ++ret.num;
      mp[parent(a.suff[i])];
    }
  }
  return ret;
}
void build(int x = 1, int l = 1, int r = n) {
  if (l == r) {
    tree[x].num = 0;
    tree[x].pre[0] = 1;
    tree[x].suff[0] = 1;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * x, l, mid);
  build(2 * x + 1, mid + 1, r);
  tree[x] = merg(tree[2 * x], tree[2 * x + 1], l, r, mid);
}
int st, en;
node query(int x = 1, int l = 1, int r = n) {
  if (l >= st && r <= en) return tree[x];
  int mid = (l + r) / 2;
  if (st > mid) return query(2 * x + 1, mid + 1, r);
  if (en <= mid) return query(2 * x, l, mid);
  return merg(query(2 * x, l, mid), query(2 * x + 1, mid + 1, r), max(st, l),
              min(en, r), mid);
}
int main() {
  cin >> n >> k;
  int m;
  cin >> m;
  int u, v;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int q;
  build();
  cin >> q;
  while (q--) {
    scanf("%d%d", &st, &en);
    node ans = query();
    set<int> s;
    for (int i = 0; i < min(k, en - st + 1); ++i) {
      s.insert(ans.pre[i]);
      s.insert(ans.suff[i]);
    }
    cout << ans.num + s.size() << endl;
  }
}
