Anica is having a peculiar dream. She is dreaming about an infinite board. On that board, an infinite table consisting of infinite rows and infinite columns containing infinite numbers is drawn. Interestingly, each number in the table appears a finite number of times.
The table is of exceptionally regular shape and its values meet the requirements of a simple recursive relation. The first cell of each row contains the ordinal number of that row. A value of a cell that is not in the first column can be calculated by adding up the number in the cell to the left of it and that same number, only written in reverse (in decimal representation).
Formally, if
, for each
1 | 2 | 4 | 8 | 16 | 77 | 154 | |
2 | 4 | 8 | 16 | 77 | 154 | 605 | |
3 | 6 | 12 | 33 | 66 | 132 | 363 | |
4 | 8 | 16 | 77 | 154 | 605 | 1111 | |
5 | 10 | 11 | 22 | 44 | 88 | 176 | |
Notice that the table is infinite only in 2 directions.
Anica hasn't shown too much interest in the board and obliviously passed by it. Behind the board, she noticed a lamp that immediately caught her attention. Anica also caught the lamp's attention, so the friendly ghost Božo came out of it.
"Anica! If you answer correctly to my
Unfortunately, Anica couldn't give an answer to the queries and woke up.
"Ah, I didn't win the Dorina cookies, but at least I have a task for COCI", she thought and went along with her business.
Input
The first line of input contains the integer
Each of the following
Output
The
Scoring
In test cases worth 50% of total points, it will hold
Sample Input 1
2
1 10
5 8
Sample Output 1
18
8
Sample Input 2
3
17 144
121 121
89 98
Sample Output 2
265
25
10
Sample Input 3
1
1 1000000000
Sample Output 3
1863025563
Comments