NSTEPS - Number Steps

Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2, ... as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has continued.

 

Illustration

 

You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...10000.

Input

The first line of the input is N, the number of test cases for this problem. In each of the N following lines, there is x, and y representing the coordinates (x, y) of a point.

Output

For each point in the input, write the number written at that point or write No Number if there is none.

Example

Input:
3
4 2
6 6
3 4

Output:
6
12
No Number

Added by:Camilo Andrés Varela León
Date:2006-11-25
Time limit:1.159s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Asia - Tehran 2000

hide comments
2018-05-30 23:40:37
@sky_scraper: When there is an O(1) algorithm for that, why do you bother computing and storing everything?

Last edit: 2018-05-30 23:41:35
2018-04-01 15:32:30
i just stored everything in a matrix and answered queries from it :-p
2018-02-04 15:39:53
@manish3749: thanks for the test cases
2018-01-11 18:45:28
Thanks to @ajayc1007 and @prasad_235
2017-10-19 17:02:17
check your conditions with other pairs too like (8,12),(12,8) etc your logic might be wrong for some pair.....basic math required.
2017-10-09 02:08:42
AC in one go, just basic maths here
2017-09-22 19:33:55
AC in one go!
Observation of the pattern leads the way to the solution
2017-09-09 15:28:14
AC in one go. Its just two line equations.
2017-08-26 12:08:07
AC in one!
2017-08-09 16:45:56
y=mx+c
just do it by it
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.