#include <bits/stdc++.h>   using namespace std;   const int p = 1000000007;   int n, x, y, g[100005], vg[100005], C, P = 1, a1, a2, a3, b, ans;   vector<int> l[100005], r[100005];   inline int ksm(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = (long long)res * a % p;       a = (long long)a * a % p;       b >>= 1;     }     return res;   }   int head[100005], to[200005], nex[200005], cnt;   inline void adde(int f, int t) {     to[++cnt] = t;     nex[cnt] = head[f];     head[f] = cnt;   }   int fa[100005], dep[100005], sz[100005], son[100005], seg[100005], top[100005];   void dfs1(int u, int pre) {     fa[u] = pre;     dep[u] = dep[pre] + 1;     sz[u] = 1;     for (int i = head[u], v; i; i = nex[i]) {       v = to[i];       if (v == pre) continue;       dfs1(v, u);       sz[u] += sz[v];       if (sz[v] > sz[son[u]]) son[u] = v;     }   }   void dfs2(int u) {     if (son[u]) {       seg[son[u]] = ++cnt;       top[son[u]] = top[u];       dfs2(son[u]);     }     for (int i = head[u], v; i; i = nex[i]) {       v = to[i];       if (top[v]) continue;       seg[v] = ++cnt;       top[v] = v;       dfs2(v);     }   }   int sum[100005], sum1[100005];   inline int query(int *a, int x) {     int res = 0;     for (; x; x -= x & -x) res = (res + a[x]) % p;     return res;   }   inline void modify(int *a, int x, int y) {     for (; x <= n + 1; x += x & -x) a[x] = (a[x] + y) % p;   }   inline int Query(int x) {     int res = ((query(sum1, 1) - query(sum, 1) * 2) % p + p) % p;     while (x) {       res = ((res + (long long)query(sum, seg[x]) * (seg[x] + 1) -               query(sum1, seg[x])) %                  p +              p) %             p;       res = ((res - (long long)query(sum, seg[top[x]] - 1) * seg[top[x]] +               query(sum1, seg[top[x]] - 1)) %                  p +              p) %             p;       x = fa[top[x]];     }     return res;   }   inline void Modify(int x, int y) {     while (x) {       modify(sum, seg[top[x]], y);       modify(sum, seg[x] + 1, (p - y) % p);       modify(sum1, seg[top[x]], (long long)y * seg[top[x]] % p);       modify(sum1, seg[x] + 1, (p - (long long)y * (seg[x] + 1) % p) % p);       x = fa[top[x]];     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &x, &y);       g[i] = y - x + 1;       vg[i] = ksm(g[i], p - 2);       l[x].push_back(i);       r[y].push_back(i);       P = (long long)P * g[i] % p;       C = max(C, y);     }     for (int i = 1; i < n; ++i) {       scanf( %d%d , &x, &y);       adde(x, y);       adde(y, x);     }     dep[0] = -1;     dfs1(1, 0);     seg[1] = top[1] = cnt = 1;     dfs2(1);     for (int c = 1; c <= C; ++c) {       for (unsigned int i = 0; i < l[c].size(); ++i) {         int x = l[c][i];         a1 = (a1 + (long long)dep[x] * vg[x]) % p;         a2 = (a2 + vg[x]) % p;         a3 = (a3 + (long long)dep[x] * vg[x] % p * vg[x]) % p;         b = (b + (long long)Query(x) * vg[x]) % p;         Modify(x, vg[x]);       }       ans = ((ans + (long long)a1 * a2 - a3 - 2 * b) % p + p) % p;       for (unsigned int i = 0; i < r[c].size(); ++i) {         int x = r[c][i];         a1 = ((a1 - (long long)dep[x] * vg[x]) % p + p) % p;         a2 = (a2 - vg[x] + p) % p;         a3 = ((a3 - (long long)dep[x] * vg[x] % p * vg[x]) % p + p) % p;         Modify(x, p - vg[x]);         b = ((b - (long long)Query(x) * vg[x]) % p + p) % p;       }     }     ans = (long long)ans * P % p;     printf( %d n , ans);     return 0;   }