Codeforces Round 993 (Div. 4) |
---|
Finished |
Wave is given five integers k, l1, r1, l2, and r2. Wave wants you to help her count the number of ordered pairs (x,y) such that all of the following are satisfied:
The first line contains an integer t (1≤t≤104) — the number of test cases.
The only line of each test case contains five integers k, l1, r1, l2, and r2 (2≤k≤109,1≤l1≤r1≤109,1≤l2≤r2≤109).
For each test case, output the number of matching ordered pairs (x,y) on a new line.
52 2 6 2 122 1 1000000000 1 10000000003 5 7 15 631000000000 1 5 6 100000000015 17 78 2596 20914861
12 1999999987 6 1 197
In the third test case, the matching ordered pairs are the following:
In the fourth test case, the only valid ordered pair is (1,1000000000)
Name |
---|