#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * t;
}
int n, k;
int S[100005], fir[100005], nxt[100005 * 20], to[100005 * 20], cnt;
int vis[100005], tim, bg[100005];
void add(int x, int y) {
  nxt[++cnt] = fir[x];
  to[cnt] = y;
  fir[x] = cnt;
  nxt[++cnt] = fir[y];
  to[cnt] = x;
  fir[y] = cnt;
}
void dfs(int x) {
  vis[x] = ++tim;
  for (int i = fir[x]; i; i = nxt[i])
    if (!vis[to[i]]) dfs(to[i]);
}
int check(int x, int l, int r) {
  if (bg[x]) return 0;
  for (int i = fir[x]; i; i = nxt[i])
    if (to[i] >= l && to[i] <= r && vis[to[i]] < vis[x]) return 0;
  return 1;
}
int main() {
  n = read(), k = read();
  for (int m = read(); m; m--) {
    int x = read(), y = read();
    add(x, y);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      dfs(i);
      bg[i] = 1;
      S[i] = 1;
    }
  for (int i = 1; i <= n; i++) S[i] += S[i - 1];
  for (int q = read(); q; q--) {
    int l = read(), r = read();
    int ans = S[r] - S[l - 1];
    for (int i = l; i <= min(r, l + 4); i++) ans += check(i, l, r);
    for (int i = max(l + 5, r - 4); i <= r; i++) ans += check(i, l, r);
    printf("%d\n", ans);
  }
}
