There are $N$ robots who work for $Y$ days and on each day they
produce some toys .on some days a few robots are given rest.
So depending on the availability of robots owner has 
made a time table which decides which robots will work on 
the particular day.
Only contiguous robots must be selected as they can form 
a link of communication among themselves.
Initially, all robots have the capacity of one toy.
On each day capacity for the chosen robot is updated i.e
capacity = capacity $+$$ ($minimum capacity of given range % $1000000007)$ .
After calculating the minimum capacity of a given range, compute
it as modulo 1000000007 ($10^9 + 7$).
After $Y$ days find the minimum capacity of the $N$ robots and compute it as modulo 1000000007 ($10^9 + 7$).   
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow. 
- Next Line contains a single integer N.
- Next Line contains a single integer Y.
- Next $Y$ lines contains l and r range of chosen robots .
-----Output:-----
For each testcase, output in a single line answer , the minimum capacity of the $N$ robots after $Y$ days and compute it as modulo 1000000007 ($10^9 + 7$) .
-----Constraints-----
- $1 \leq T \leq 100$
- $100 \leq N \leq 10^4$
- $200 \leq Y \leq 1000$
- $0<=l , r<=N-1$  , $l<=r$
-----Sample Input:-----
1
5
4
0 3
1 2
4 4
0 4
-----Sample Output:-----
4
-----EXPLANATION:-----
Initial capacity of the $5$ robots
1 1 1 1 1 
Minimum in range [0,3] = 1
Update the capacity in the range [0,3]
Now capacity becomes, 
Day 1 - 2 2 2 2 1
Similarly capacities changes for each day 
Day 2 - 2 4 4 2 1
Day 3 - 2 4 4 2 2
Day 4 - 4 6 6 4 4
so after 4 days minimum capacity is $4$.
MAX = 100005
tree = [0] * MAX; 
lazy = [0] * MAX;
 
def updateRangeUtil(si, ss, se, us, ue, diff) :
    if (lazy[si] != 0) :
        tree[si] += lazy[si];
        if (ss != se) :
            lazy[si * 2 + 1] += lazy[si];
            lazy[si * 2 + 2] += lazy[si];
        lazy[si] = 0;
 
    if (ss > se or ss > ue or se < us) :
        return; 
 
    if (ss >= us and se <= ue) :
        tree[si] += diff;
        if (ss != se) :
            lazy[si * 2 + 1] += diff;
            lazy[si * 2 + 2] += diff;
        return; 
 
    mid = (ss + se) // 2;
    updateRangeUtil(si * 2 + 1, ss,mid, us, ue, diff);
    updateRangeUtil(si * 2 + 2, mid + 1,se, us, ue, diff);
    tree[si] = min(tree[si * 2 + 1],tree[si * 2 + 2]); 
 
def updateRange(n, us, ue, diff) : 
    updateRangeUtil(0, 0, n - 1, us, ue, diff); 
 
def getSumUtil(ss, se, qs, qe, si) :
    if (lazy[si] != 0) :
        tree[si] += lazy[si];
        if (ss != se) :
            lazy[si * 2 + 1] += lazy[si];
            lazy[si * 2 + 2] += lazy[si];
        lazy[si] = 0;
 
    if (ss > se or ss > qe or se < qs) :
        return 10e9; 
 
    if (ss >= qs and se <= qe) :
        return tree[si]; 
 
    mid = (ss + se) // 2; 
    return min(getSumUtil(ss, mid, qs, qe, 2 * si + 1),getSumUtil(mid + 1, se, qs, qe, 2 * si + 2)); 
 
def getSum(n, qs, qe) : 
    if (qs < 0 or qe > n - 1 or qs > qe) :
        #print("Invalid Input", end = "");
        return -1;
 
    return getSumUtil(0, n - 1, qs, qe, 0); 
 
def constructSTUtil(arr, ss, se, si) : 
    if (ss > se) :
        return;
    if (ss == se) :
        tree[si] = arr[ss];
        return; 
    mid = (ss + se) // 2;
    constructSTUtil(arr, ss, mid, si * 2 + 1);
    constructSTUtil(arr, mid + 1, se, si * 2 + 2);
    tree[si] = min(tree[si * 2 + 1], tree[si * 2 + 2]); 
 
def constructST(arr, n) :
    constructSTUtil(arr, 0, n - 1, 0); 
 
# Driver code 
for _ in range(int(input())):
    tree = [0] * MAX; 
    lazy = [0] * MAX;
    n=int(input());
    y=int(input());
    arr=[1]*n;
    constructST(arr, n);
    for xyz in range(y):
        l,r=list(map(int,input().split()));
        updateRange(n, l, r, getSum(n, l, r)%1000000007);
    print((getSum(n, 0, n-1)%1000000007));

MAX = 100005
tree = [0] * MAX; 
lazy = [0] * MAX;
 
def updateRangeUtil(si, ss, se, us, ue, diff) :
    if (lazy[si] != 0) :
        tree[si] += lazy[si];
        if (ss != se) :
            lazy[si * 2 + 1] += lazy[si];
            lazy[si * 2 + 2] += lazy[si];
        lazy[si] = 0;
 
    if (ss > se or ss > ue or se < us) :
        return; 
 
    if (ss >= us and se <= ue) :
        tree[si] += diff;
        if (ss != se) :
            lazy[si * 2 + 1] += diff;
            lazy[si * 2 + 2] += diff;
        return; 
 
    mid = (ss + se) // 2;
    updateRangeUtil(si * 2 + 1, ss,mid, us, ue, diff);
    updateRangeUtil(si * 2 + 2, mid + 1,se, us, ue, diff);
    tree[si] = min(tree[si * 2 + 1],tree[si * 2 + 2]); 
 
def updateRange(n, us, ue, diff) : 
    updateRangeUtil(0, 0, n - 1, us, ue, diff); 
 
def getSumUtil(ss, se, qs, qe, si) :
    if (lazy[si] != 0) :
        tree[si] += lazy[si];
        if (ss != se) :
            lazy[si * 2 + 1] += lazy[si];
            lazy[si * 2 + 2] += lazy[si];
        lazy[si] = 0;
 
    if (ss > se or ss > qe or se < qs) :
        return 10e9; 
 
    if (ss >= qs and se <= qe) :
        return tree[si]; 
 
    mid = (ss + se) // 2; 
    return min(getSumUtil(ss, mid, qs, qe, 2 * si + 1),getSumUtil(mid + 1, se, qs, qe, 2 * si + 2)); 
 
def getSum(n, qs, qe) : 
    if (qs < 0 or qe > n - 1 or qs > qe) :
        #print("Invalid Input", end = "");
        return -1;
 
    return getSumUtil(0, n - 1, qs, qe, 0); 
 
def constructSTUtil(arr, ss, se, si) : 
    if (ss > se) :
        return;
    if (ss == se) :
        tree[si] = arr[ss];
        return; 
    mid = (ss + se) // 2;
    constructSTUtil(arr, ss, mid, si * 2 + 1);
    constructSTUtil(arr, mid + 1, se, si * 2 + 2);
    tree[si] = min(tree[si * 2 + 1], tree[si * 2 + 2]); 
 
def constructST(arr, n) :
    constructSTUtil(arr, 0, n - 1, 0); 
 
# Driver code 
for _ in range(int(input())):
    tree = [0] * MAX; 
    lazy = [0] * MAX;
    n=int(input());
    y=int(input());
    arr=[1]*n;
    constructST(arr, n);
    for xyz in range(y):
        l,r=list(map(int,input().split()));
        updateRange(n, l, r, getSum(n, l, r)%1000000007);
    print((getSum(n, 0, n-1)%1000000007));
