#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y, q, s[6 * 100005], ch[6 * 100005][2], f[100005], Ans[100005],
    value[6 * 100005], Max[6 * 100005], Max_num[6 * 100005], fa[6 * 100005];
bool lazy[6 * 100005];
struct thing {
  int x, y, num, val;
} ask[100005], edg[6 * 100005];
vector<int> G_ask[100005], G_edg[100005];
inline bool isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
void push_up(int x) {
  Max[0] = 0;
  Max[x] = value[x], Max_num[x] = x;
  if (Max[x] < Max[ch[x][0]]) {
    Max[x] = Max[ch[x][0]];
    Max_num[x] = Max_num[ch[x][0]];
  }
  if (Max[x] < Max[ch[x][1]]) {
    Max[x] = Max[ch[x][1]];
    Max_num[x] = Max_num[ch[x][1]];
  }
}
void rotate(int x) {
  int y = fa[x], z = fa[y];
  int d = ch[y][0] == x ? 0 : 1;
  if (!isroot(y)) {
    if (ch[z][0] == y)
      ch[z][0] = x;
    else
      ch[z][1] = x;
  }
  fa[y] = x, fa[x] = z, fa[ch[x][d ^ 1]] = y;
  ch[y][d] = ch[x][d ^ 1], ch[x][d ^ 1] = y;
  push_up(y), push_up(x);
}
inline void push_down(int x) {
  if (!lazy[x]) return;
  int ls = ch[x][0], rs = ch[x][1];
  lazy[x] ^= 1, lazy[ls] ^= 1;
  lazy[rs] ^= 1;
  swap(ch[ls][0], ch[ls][1]);
  swap(ch[rs][0], ch[rs][1]);
}
void splay(int x) {
  int tot = 0;
  s[++tot] = x;
  for (int i = x; !isroot(i); i = fa[i]) s[++tot] = fa[i];
  for (; tot; tot--) push_down(s[tot]);
  while (!isroot(x)) {
    int y = fa[x], z = fa[y];
    if (!isroot(y)) {
      if ((ch[z][0] == y) ^ (ch[y][0] == x))
        rotate(x);
      else
        rotate(y);
    }
    rotate(x);
  }
}
void access(int x) {
  int t = 0;
  while (x) {
    splay(x);
    ch[x][1] = t;
    push_up(x);
    t = x, x = fa[x];
  }
}
int findroot(int x) {
  splay(x);
  while (ch[x][0]) x = ch[x][0];
  return x;
}
void makeroot(int x) {
  access(x), splay(x);
  swap(ch[x][0], ch[x][1]);
  lazy[x] ^= 1;
}
void link(int x, int y) {
  makeroot(x);
  fa[x] = y;
}
void cut(int x, int y) {
  makeroot(x), access(y), splay(y), ch[y][0] = fa[x] = 0;
  push_up(y);
}
bool islink(int x, int y) {
  makeroot(x);
  access(y);
  return findroot(y) == x;
}
int lowbit(int x) { return x & (-x); }
void Insert(int x, int k) {
  while (x <= n) {
    f[x] += k;
    x += lowbit(x);
  }
}
int Find_sum(int x) {
  int ans = 0;
  while (x) {
    ans += f[x];
    x -= lowbit(x);
  }
  return ans;
}
int main() {
  memset(Max, 0, sizeof(Max));
  memset(value, 0, sizeof(value));
  scanf("%d%d", &n, &k);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &edg[i].x, &edg[i].y);
    if (edg[i].x > edg[i].y) swap(edg[i].x, edg[i].y);
    edg[i].val = edg[i].y;
    Max[i + n] = value[i + n] = edg[i].val;
    Max_num[i + n] = i + n;
    G_edg[edg[i].x].push_back(i);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &ask[i].x, &ask[i].y);
    G_ask[ask[i].x].push_back(i);
  }
  for (int i = n; i; i--) {
    for (int j = 0; j < G_edg[i].size(); j++) {
      int e = G_edg[i][j];
      int x = edg[e].x, y = edg[e].y, val = edg[e].val;
      if (islink(x, y)) {
        if (Max[y] > val) {
          int u = edg[Max_num[y] - n].x, v = edg[Max_num[y] - n].y,
              t = Max_num[y];
          Insert(Max[y], -1);
          Insert(val, 1);
          cut(u, t);
          cut(t, v);
          link(x, n + e);
          link(n + e, y);
        }
      } else {
        Insert(val, 1);
        link(x, n + e);
        link(n + e, y);
      }
    }
    for (int j = 0; j < G_ask[i].size(); j++) {
      int v = G_ask[i][j];
      Ans[v] = ask[v].y - ask[v].x + 1 - Find_sum(ask[v].y);
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", Ans[i]);
}
