#include <bits/stdc++.h>
using namespace std;
constexpr int N = 125252;
const int C = 400, B = 300;
int data[N], unitednum;
pair<int, int> rec[2521];
int rec_tail;
int recunitednum;
inline void init(int n) {
  for (int i = 0; i < (int)(n); ++i) data[i] = -1;
  unitednum = 0;
}
inline void snapshot() {
  rec_tail = 0;
  recunitednum = unitednum;
}
inline void rollback() {
  for (int i = (int)(rec_tail)-1; i >= (int)(0); --i)
    data[rec[i].first] = rec[i].second;
  unitednum = recunitednum;
}
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int recroot(int x) {
  if (data[x] < 0)
    return x;
  else {
    return recroot(data[x]);
  }
}
void unite(int a, int b) {
  a = root(a);
  b = root(b);
  if (a != b) {
    if (data[a] > data[b]) swap(a, b);
    data[a] += data[b];
    data[b] = a;
    unitednum++;
  }
}
int recunite(int a, int b) {
  a = recroot(a);
  b = recroot(b);
  if (a != b) {
    if (data[a] > data[b]) swap(a, b);
    rec[rec_tail++] = pair<int, int>(a, data[a]);
    rec[rec_tail++] = pair<int, int>(b, data[b]);
    data[a] += data[b];
    data[b] = a;
    unitednum++;
  }
}
int n, k, m, q;
vector<pair<pair<int, int>, int>> qs[C];
int ans[N];
bitset<10> g[N];
int naive(int l, int r) {
  snapshot();
  for (int i = (int)(l); i < (int)(r + 1); ++i) {
    for (int j = 0; j < (int)(5); ++j)
      if (g[i].test(j) && i - j - 1 >= l) {
        recunite(i, i - j - 1);
      }
  }
  int ret = r - l + 1 - unitednum;
  rollback();
  return ret;
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 0; i < (int)(m); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    if (u > v) swap(u, v);
    int d = v - u;
    g[u].set(d + 4);
    g[v].set(d - 1);
  }
  scanf("%d", &q);
  init(n);
  for (int i = 0; i < (int)(q); ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l;
    --r;
    if (r - l + 1 <= B) {
      ans[i] = naive(l, r);
    } else {
      qs[l / B].push_back(make_pair(pair<int, int>(l, r), i));
    }
  }
  for (int i = 0; i < (int)(C); ++i) {
    if (qs[i].size() == 0) continue;
    sort((qs[i]).begin(), (qs[i]).end(),
         [](pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
           return a.first.second < b.first.second;
         });
    int lng = (i + 1) * B;
    int rig = (i + 1) * B;
    init(n);
    for (auto P : qs[i]) {
      int l = P.first.first;
      int r = P.first.second;
      int id = P.second;
      while (rig <= r) {
        for (int j = 0; j < (int)(5); ++j)
          if (g[rig].test(j) && rig - j - 1 >= lng) {
            unite(rig, rig - j - 1);
          }
        rig++;
      }
      snapshot();
      for (int p = (int)(l); p < (int)(lng); ++p) {
        for (int j = 0; j < (int)(5); ++j)
          if (g[p].test(j + 5) && p + j + 1 <= r) {
            recunite(p, p + j + 1);
          }
      }
      ans[id] = r - l + 1 - unitednum;
      rollback();
    }
  }
  for (int i = 0; i < (int)(q); ++i) printf("%d\n", ans[i]);
  return 0;
}
