#### Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

## Problem Description

Ranald is eating flowers for lunch today. He has bought an infinite supply of red and white flowers.

Ranald eats flowers one by one, but he has decided that he must only eat white flowers in consecutive groups of *K*. There are no limitations on how and when he eats the red flowers.

There are *D* days he will be planning his lunches for. On each day *i*, he wants to eat between *A _{i}* and

*B*flowers. Help him find out what is the number of possible lunches he can have for each day. Two ways are considered different if at some point in time, he eats one type of flower in one way and another type of flower in another. Since this number can be very large, output it modulo 10

_{i}^{9}+ 7.

## Limits

For all subtasks: 1 ≤ D ≤ 10^{5}.

Subtask 1 (17%): 1 ≤ K ≤ 18, 1 ≤ A_{i} ≤ B_{i} ≤ 18.

Subtask 2 (23%): K = 1, 1 ≤ A_{i} ≤ B_{i} ≤ 10^{6}.

Subtask 3 (24%): 1 ≤ K ≤ 10^{6}, 1 ≤ A_{i} = B_{i} ≤ 10^{6}.

Subtask 4 (36%): 1 ≤ K ≤ 10^{6}, 1 ≤ A_{i} ≤ B_{i} ≤ 10^{6}.

Subtask 5 (0%): Sample Testcases.

## Input

The first line of input contains two integers, *K* and *D*.

The next *D* lines of input contains two integers each, *A _{i}* and

*B*for each day.

_{i}## Output

The output should contain *D* lines, with line *i* containing the number of possible lunches Ranald could have on day *i*, modulo 10^{9} + 7.

## Sample Testcase 1

### Input

2 3 1 3 2 3 4 4

### Output

6 5 5

### Explanation

For K = 2, Rar can eat "R", "RR", "WW", "RRR", "RWW", "WWR", "WWWW" or "RWWR".

### Tags

### Subtasks and Limits

Subtask | Score | #TC | Time | Memory | Scoring |
---|---|---|---|---|---|

1 | 17 | 21 | 1s | 256MB | Minimum |

2 | 23 | 20 | 1s | 256MB | Minimum |

3 | 24 | 20 | 1s | 256MB | Minimum |

4 | 36 | 81 | 1s | 256MB | Minimum |

5 | 0 | 1 | 1s | 256MB | Minimum |

### Judge Compile Command

g++-7 ans.cpp -o flowers -Wall -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512