#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
  scf(x);
  scf(y);
  scf(z);
  return scf(w);
}
const int N = 2e5 + 100;
namespace LCT {
static const int maxn = N;
struct node {
  node *ch[2], *fa, *Min;
  int val, fl;
  pair<int, int> con;
  inline bool isr() const {
    return !fa || (fa->ch[0] != this && fa->ch[1] != this);
  }
  inline int dir() const { return fa->ch[1] == this; }
  inline void push() {
    if (fl) {
      swap(ch[0], ch[1]);
      (ch[0]) && (ch[0]->fl ^= 1);
      (ch[1]) && (ch[1]->fl ^= 1);
      fl = 0;
    }
    return;
  }
  inline void pull() {
    Min = this;
    (ch[0] && ch[0]->Min->val < Min->val) && (Min = ch[0]->Min);
    (ch[1] && ch[1]->Min->val < Min->val) && (Min = ch[1]->Min);
    return;
  }
  inline void setc(const int &d, node *u) {
    ch[d] = u;
    if (u) u->fa = this;
    return;
  }
} pool[maxn];
node *sta[maxn];
inline void rot(node *u) {
  node *f = u->fa;
  int d = u->dir();
  if (f->isr())
    u->fa = f->fa;
  else
    f->fa->setc(f->dir(), u);
  f->setc(d, u->ch[!d]);
  u->setc(!d, f);
  f->pull();
  return;
}
inline void splay(node *u) {
  node *v = u;
  auto t = sta;
  while (!v->isr()) {
    t++;
    *t = v;
    v = v->fa;
  }
  v->push();
  while (t != sta) (*t)->push(), t--;
  while (!u->isr()) {
    if (!u->fa->isr()) (u->dir() == u->fa->dir()) ? rot(u->fa) : rot(u);
    rot(u);
  }
  return u->pull();
}
inline node *access(node *u) {
  node *v = 0;
  for (; u; u = u->fa) {
    splay(u);
    u->ch[1] = v;
    (v = u)->pull();
  }
  return v;
}
inline void mroot(node *u) {
  u = access(u);
  u->fl ^= 1;
  u->push();
  return;
}
inline void expose(node *u, node *v) {
  mroot(u);
  access(v);
  splay(u);
  return;
}
inline void link(node *u, node *v) {
  mroot(u);
  mroot(v);
  u->setc(1, v);
  return;
}
inline void cut(node *u, node *v) {
  expose(u, v);
  u->ch[1] = v->fa = 0;
  return;
}
}  // namespace LCT
namespace BIT {
static const int maxn = N;
int L, n;
int num[maxn];
inline void init(int l, int r) {
  L = l - 1;
  n = (r - L + 1);
  return;
}
inline void modify(int i, const int &x) {
  i = i - L;
  for (; i <= n; i += (i & (-i))) num[i] += x;
  return;
}
inline int query(int i) {
  i = i - L;
  int ret = 0;
  for (; i; i ^= (i & (-i))) ret += num[i];
  return ret;
}
}  // namespace BIT
int n, m, Q;
vector<int> g[N];
vector<pair<int, int> > q[N];
int ans[N];
auto p_ans = ans;
auto p_g = g;
inline int MIN(const int &x, const int &y) { return x < y ? x : y; }
inline int MAX(const int &x, const int &y) { return x < y ? y : x; }
int main() {
  scf(n, m, m);
  for (int i = 0; i < (m); i++) {
    int u, v;
    scf(u, v);
    int mn = MIN(u, v), mx = MAX(u, v);
    g[mx].push_back(mn);
  }
  scf(Q);
  for (int i = (1); i <= (Q); i++) {
    int l, r;
    scf(l, r);
    q[r].push_back({l, i});
    p_ans++;
    *p_ans = r - l + 1;
  }
  auto p_pool = LCT::pool, t = p_pool;
  for (int i = (1); i <= (n + 1); i++) p_pool++, p_pool->val = iinf;
  BIT::init(0, n);
  for (int i = (1); i <= (n); i++) {
    t++;
    LCT::node *v = LCT::pool + n + 1;
    p_pool++;
    p_pool->val = 0;
    p_pool->con = {i, n + 1};
    LCT::link(t, p_pool);
    LCT::link(v, p_pool);
  }
  BIT::modify(0, n);
  auto u = LCT::pool;
  for (int i = (1); i <= (n); i++) {
    p_g++;
    u++;
    for (int j : *p_g) {
      LCT::node *v = LCT::pool + j;
      LCT::expose(u, v);
      if (j > u->Min->val) {
        LCT::node *e = u->Min;
        LCT::cut(LCT::pool + e->con.first, e);
        LCT::cut(LCT::pool + e->con.second, e);
        BIT::modify(e->val, -1);
        e->val = j;
        BIT::modify(e->val, 1);
        e->con = {i, j};
        LCT::link(LCT::pool + i, e);
        LCT::link(LCT::pool + j, e);
      }
    }
    for (pair<int, int> x : q[i]) {
      ans[x.second] -= (n - BIT::query(x.first - 1));
    }
  }
  for (int i = (1); i <= (Q); i++) printf("%d\n", ans[i]);
  return 0;
}
