#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[1 << 16], *S, *T;     if (S == T) {       T = (S = buf) + fread(buf, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline int read() {     int x = 0, f = 1;     char ch = gc();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = gc();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = gc();     return x * f;   }   int n, K, m, c[100010 + 500010][2], v[100010 + 500010], fa[100010 + 500010],       mn[100010 + 500010], ans[100010], cc[100010], q[100010];   bool rev[100010 + 500010];   struct edge {     int x, y;   } e[500010];   inline bool cmp(edge a, edge b) { return a.y < b.y; }   struct query {     int l, r, id;     friend bool operator<(query a, query b) { return a.r < b.r; }   } qq[100010];   inline void add(int x, int val) {     for (; x <= n; x += x & -x) cc[x] += val;   }   inline int ask(int x) {     int res = 0;     for (; x; x -= x & -x) res += cc[x];     return res;   }   inline bool isroot(int x) { return x != c[fa[x]][0] && x != c[fa[x]][1]; }   inline void update(int p) {     int l = c[p][0], r = c[p][1];     mn[p] = p;     if (v[mn[l]] < v[mn[p]]) mn[p] = mn[l];     if (v[mn[r]] < v[mn[p]]) mn[p] = mn[r];   }   inline void pushdown(int p) {     if (!rev[p]) return;     rev[p] = 0;     swap(c[p][0], c[p][1]);     rev[c[p][0]] ^= 1;     rev[c[p][1]] ^= 1;   }   inline void rotate(int x) {     int y = fa[x], z = fa[y], l = x == c[y][1], r = l ^ 1;     if (!isroot(y)) c[z][y == c[z][1]] = x;     fa[c[x][r]] = y;     fa[y] = x;     fa[x] = z;     c[y][l] = c[x][r];     c[x][r] = y;     update(y);     update(x);   }   inline void splay(int x) {     int top = 0;     q[++top] = x;     for (int xx = x; !isroot(xx); xx = fa[xx]) q[++top] = fa[xx];     while (top) pushdown(q[top--]);     while (!isroot(x)) {       int y = fa[x], z = fa[y];       if (!isroot(y)) {         if (x == c[y][1] ^ y == c[z][1])           rotate(x);         else           rotate(y);       }       rotate(x);     }   }   inline void access(int x) {     int y = 0;     while (x) {       splay(x);       c[x][1] = y;       update(x);       y = x;       x = fa[x];     }   }   inline void makeroot(int x) {     access(x);     splay(x);     rev[x] ^= 1;   }   inline int find(int x) {     access(x);     splay(x);     while (c[x][0]) x = c[x][0];     return x;   }   inline void link(int x, int y) {     makeroot(x);     fa[x] = y;   }   inline void cut(int x, int y) {     makeroot(x);     access(y);     splay(y);     c[y][0] = fa[x] = 0;     update(y);   }   inline int qmin(int x, int y) {     makeroot(x);     access(y);     splay(y);     return mn[y];   }   inline void ins(int id) {     int x = e[id].x, y = e[id].y;     if (find(x) != find(y)) {       link(x, id + n), link(id + n, y), add(n - x + 1, 1);       return;     }     int z = qmin(x, y);     if (v[z] >= v[id + n]) return;     cut(z, e[z - n].x);     cut(z, e[z - n].y);     add(n - v[z] + 1, -1);     link(x, id + n);     link(id + n, y);     add(n - x + 1, 1);   }   int main() {     n = read();     K = read();     m = read();     v[0] = 0x3f3f3f3f;     for (int i = 1; i <= m; ++i) {       e[i].x = read();       e[i].y = read();       if (e[i].x > e[i].y) swap(e[i].x, e[i].y);     }     sort(e + 1, e + m + 1, cmp);     int Q = read();     for (int i = 1; i <= m; ++i) v[i + n] = e[i].x;     for (int i = 1; i <= n; ++i) v[i] = 0x3f3f3f3f;     for (int i = 1; i <= Q; ++i) qq[i].l = read(), qq[i].r = read(), qq[i].id = i;     sort(qq + 1, qq + Q + 1);     int now = 1;     for (int i = 1; i <= Q; ++i) {       while (now <= m && e[now].y <= qq[i].r) ins(now), ++now;       ans[qq[i].id] = qq[i].r - qq[i].l + 1 - ask(n - qq[i].l + 1);     }     for (int i = 1; i <= Q; ++i) printf( %d n , ans[i]);     return 0;   }