#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int res = 0;
  int neg;
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9' || ch == '-') {
      if (ch == '-')
        neg = -1;
      else
        neg = 1, res = ch - '0';
      break;
    }
  }
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9')
      res *= 10, res += ch - '0';
    else
      break;
  }
  return res * neg;
}
const int maxn = 100020;
const int maxm = 1000020;
const int MOd = 1e9 + 7;
const int K = 350;
int dad[maxn], a, k, b;
int gec[maxn];
int num, ans[maxn];
vector<int> g;
int find(int n) {
  if (n == dad[n]) return n;
  return dad[n] = find(dad[n]);
}
void merge(int j, int k) {
  j = find(j);
  k = find(k);
  if (j != k) dad[j] = k, num--;
}
vector<int> nex[maxn], pre[maxn];
bool comp(const pair<pair<int, int>, int> &a,
          const pair<pair<int, int>, int> &b) {
  if ((a.first.first / K) == (b.first.first / K))
    return a.first.second < b.first.second;
  return (a.first.first / K) < (b.first.first / K);
}
int main() {
  int a, kk, b;
  scanf("%d %d %d", &a, &kk, &b);
  for (int i = 1, j, k; i <= b; i++) {
    scanf("%d %d", &j, &k);
    if (j > k) swap(j, k);
    nex[j].push_back(k);
    pre[k].push_back(j);
  }
  int q;
  scanf("%d", &q);
  vector<pair<pair<int, int>, int> > v;
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    v.push_back(pair<pair<int, int>, int>(pair<int, int>(l, r), i));
  }
  sort(v.begin(), v.end(), comp);
  int last = -1, R = 0, L = 0;
  for (int i = 0; i < v.size(); i++) {
    if ((v[i].first.first / K) != last) {
      last = v[i].first.first / K;
      for (int j = 1; j <= a; j++) dad[j] = j;
      L = (last + 1) * K;
      R = L - 1;
      num = 0;
    }
    int l = v[i].first.first;
    int r = v[i].first.second;
    while (R < r) {
      ++R;
      num++;
      for (int j = 0; j < pre[R].size(); j++)
        if (pre[R][j] >= L) merge(pre[R][j], R);
    }
    g.clear();
    int oldnum = num;
    for (int j = min(L - 1, r); j >= l; j--) {
      dad[j] = j;
      num++;
      for (int k = 0; k < nex[j].size(); k++) {
        int h = nex[j][k];
        if (h <= r) {
          h = find(h);
          if (gec[h]) h = find(gec[h]);
          if (h != j) {
            num--;
            if (h < L)
              dad[h] = j;
            else
              gec[h] = j, g.push_back(h);
          }
        }
      }
    }
    ans[v[i].second] = num;
    num = oldnum;
    for (int j = 0; j < g.size(); j++) gec[g[j]] = 0;
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
