#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const long long MOD = 1e9 + 7;   long long f[N << 2], lazy[N << 2], a[N], b[N], c[N];   void up(int x, int l, int r, long long y) {     f[x] = (f[x] + y * (r - l + 1)) % MOD;     lazy[x] = (lazy[x] + y) % MOD;   }   void push_down(int x, int l, int r) {     int mid = (l + r) / 2;     up(x << 1, l, mid, lazy[x]);     up(x << 1 | 1, mid + 1, r, lazy[x]);     lazy[x] = 0;   }   void update(int x, int l, int r, int left, int right, long long y) {     if (left > r || right < l) return;     if (left <= l && right >= r) {       up(x, l, r, y);       return;     }     push_down(x, l, r);     int mid = (l + r) / 2;     update(x << 1, l, mid, left, right, y);     update(x << 1 | 1, mid + 1, r, left, right, y);     f[x] = (f[x << 1] + f[x << 1 | 1]) % MOD;   }   long long query(int x, int l, int r, int left, int right) {     if (left > r || right < l) return 0;     if (left <= l && right >= r) return f[x];     push_down(x, l, r);     int mid = (l + r) / 2;     return (query(x << 1, l, mid, left, right) +             query(x << 1 | 1, mid + 1, r, left, right)) %            MOD;   }   int sz[N], son[N], l[N], r[N], n;   vector<int> p[N];   long long res, ans;   void getsize(int x, int fa) {     sz[x] = 1;     son[x] = -1;     for (int v : p[x])       if (v != fa) {         getsize(v, x);         sz[x] += sz[v];         if (son[x] == -1 || sz[v] > sz[son[x]]) son[x] = v;       }   }   void calc(int x, long long y, int op) {     if (op) {       long long tmp = a[r[x]] - a[l[x] - 1] -                       query(1, 1, 100000, l[x], r[x]) * 2 - y * (r[x] - l[x] + 1);       tmp = (tmp % MOD + MOD) % MOD;       res = (res + tmp * y) % MOD;     }     update(1, 1, 100000, l[x], r[x], y);   }   void clear(int x, int fa) {     calc(x, -c[x] + MOD, 0);     for (int v : p[x])       if (v != fa) clear(v, x);   }   void add(int x, int fa) {     calc(x, c[x], 1);     for (int v : p[x])       if (v != fa) add(v, x);   }   void gao(int x, int fa) {     for (int v : p[x])       if (v != fa && v != son[x]) {         gao(v, x);         clear(v, x);         res = 0;       }     if (son[x] != -1) gao(son[x], x);     for (int v : p[x])       if (v != fa && v != son[x]) {         add(v, x);       }     calc(x, c[x], 1);     ans = (ans + res) % MOD;   }   long long qpow(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y & 1) z = z * x % MOD;       x = x * x % MOD;       y /= 2;     }     return z;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l[i], &r[i]);       long long t = qpow(r[i] - l[i] + 1, MOD - 2);       c[i] = t;       a[l[i]] = (a[l[i]] + t) % MOD;       a[r[i] + 1] = (a[r[i] + 1] - t + MOD) % MOD;     }     for (int i = 1; i < N; i++) b[i] = (b[i - 1] + a[i]) % MOD;     memset(a, 0, sizeof(a));     for (int i = 1; i < N; i++) a[i] = (a[i - 1] + b[i]) % MOD;     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       p[u].push_back(v);       p[v].push_back(u);     }     getsize(1, 0);     gao(1, 0);     for (int i = 1; i <= n; i++) {       ans = ans * (r[i] - l[i] + 1) % MOD;     }     printf( %lld , ans);     return 0;   }