#include <bits/stdc++.h>   namespace io {   const char endl =   n ;   template <typename T>   inline void chkmin(T &a, T b) {     a > b ? a = b : 0;   }   template <typename T>   inline void chkmax(T &a, T b) {     a < b ? a = b : 0;   }   struct Stream {     template <class T>     Stream operator>>(T &x) {       x = 0;       register int f = 1;       register char c;       while (!isdigit(c = getchar()))         if (c ==  - ) f = -1;       while (x = (x << 1) + (x << 3) + (c ^ 48), isdigit(c = getchar()))         ;       return x *= f, *this;     }     Stream operator>>(char *str) { return scanf( %s , str), *this; }     template <class T>     Stream operator<<(T x) {       static char out[35];       static unsigned int top = 0;       if (x < 0) x = -x, putchar( - );       while (out[++top] = x % 10 ^ 48, x /= 10, x)         ;       while (putchar(out[top--]), top)         ;       return *this;     }     Stream operator<<(char *str) { return printf( %s , str), *this; }     Stream operator<<(char ch) { return putchar(ch), *this; }   } cin, cout;   }  // namespace io   const int N = 3e5 + 10;   int ver[N * 2], nxt[N * 2], head[N], tot, n, m, stk[N], top, L[N];   inline void add(int u, int v) {     ver[++tot] = v, nxt[tot] = head[u], head[u] = tot;   }   bool vis[N], loop[N];   void DFS(int u, int fa) {     vis[u] = 1;     stk[++top] = u;     for (int i = head[u]; i; i = nxt[i]) {       int v = ver[i];       if (loop[v] or v == fa) continue;       if (!vis[v])         DFS(v, u);       else {         int Max = 0, Min = n + 1;         for (int j = top, y;; j--) {           y = stk[j];           io::chkmin(Min, y);           io::chkmax(Max, y);           loop[y] = 1;           if (stk[j] == v) break;         }         if (!L[Max])           L[Max] = Min;         else           io::chkmax(L[Max], Min);       }     }     top--;   }   long long sum[N];   int main() {     io::cin >> n >> m;     for (register unsigned int i = 1, iend = m; i <= iend; ++i) {       int u, v;       io::cin >> u >> v;       add(u, v), add(v, u);     }     for (register unsigned int i = 1, iend = n; i <= iend; ++i)       if (!vis[i]) DFS(i, i);     for (register unsigned int i = 1, iend = n; i <= iend; ++i) {       io::chkmax(L[i], L[i - 1]);       sum[i] = sum[i - 1] + L[i];     }     int Q;     io::cin >> Q;     while (Q--) {       int x, y;       io::cin >> x >> y;       int l = x, r = y, p = y + 1;       long long ans = 0;       while (l <= r) {         int mid = (l + r) >> 1;         if (L[mid] >= x)           r = mid - 1, p = mid;         else           l = mid + 1;       }       ans = 1ll * (x + y) * (y - x + 1) / 2 - (sum[y] - sum[p - 1]) -             1ll * (x - 1) * (p - x);       io::cout << ans << io::endl;     }     return 0;   }   