#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MS(a, b) memset(a, b, sizeof a) #define LB(x) ((x) & (-x)) #define REP(a, b, c) for(int a = b; a < c; ++a) #define REP1(a, b, c) for(int a = b; a <= c; ++a) using namespace std; typedef long long ll; const int N = 1e5+17; const ll MOD = 1e9+7; int n, l, r; struct P{ int x; int id; P(int x = 0, int id = 0) : x(x), id(id) {} bool operator < (const P& a)const { return x < a.x || (x == a.x && id > a.id) ; } }; vector

v; ll po[N]; void init() { po[0] = 1LL; REP1(i, 1, N) po[i] = (po[i-1] * 2) % MOD; return ; } long long val(int y) { return (po[y] - 1) * po[n-y] % MOD; } int main() { #ifdef PIT freopen("1002.in", "r", stdin); #endif // PIT int T; init(); scanf("%d", &T); while(T--) { scanf("%d", &n); v.clear(); REP(i, 0, n) { scanf("%d %d", &l, &r); v.push_back(P(l, 1)); v.push_back(P(r, -1)); } int len = v.size(); sort(v.begin(), v.end()); //for(int i = 0; i < len; ++i) printf("%d %d ", v[i].x, v[i].id); puts(""); int k = 1; long long res = 0; for(int i = 1; i < len; ++i) { if(v[i].id == 1) { int dis = v[i].x - v[i-1].x; res = (res + (val(k) * dis % MOD)) % MOD ; ++k; } else if(v[i].id == -1) { int dis = v[i].x - v[i-1].x; res = (res + (val(k) * dis % MOD)) % MOD ; --k; } } printf("%I64d\n", res); } return 0; }