SNGLOOP1  Easiest Loop 1
Ileana D'Cruz is taking programming classes but she is having problem in understanding while loops. She is working on following set of instructions 
INTEGER I = 0, S, U = 10^{10};
WHILE (I < U) {
S = (3 * S) + (5 * I);
I = I + 1;
}
Let S_{k} be the value assigned to INTEGER S for the iteration I = (k + 1) and n, m, p be positive integers such that m > n. Ileana knows the values of n and m but she forgot the initial value of S. She is trying to find the unit digit of p. Any initial value of S may be used. She also knows the following equality 
(2 * n + 3) * (p  1) + (4 / 5) * [(p * S_{n})  S_{m}] = 2 * (m  n)
Input
First line of input is T(total no. of test cases). Each of next T lines contains two integers n and m.
Output
Print unit digit of p (p % 10) for each test case in separated lines.
Example
Input: 1 2 3 Output: 3
Constraints
T < 10001
Explanation
Let S = 2
S_{0} = 6
S_{1} = 23
S_{2} = 79
S_{3} = 252
Now solving the equation gives p = 3.
hide comments
prabhav_123:
20190108 19:02:36
getting back to the very basic concept of physics's derivations, finally got me an AC! Pheww Last edit: 20190108 19:26:38 

mcjoshi:
20160227 13:25:54
took my 3 hours! AC


KD :
20160101 19:17:13
Damn easy


Siddharth Singh:
20151226 12:49:34
Interesting One , the given explanation Helped me device a trial an error formula which to my surprise worked :D


vagesh_verma:
20150816 10:05:04
Last edit: 20150816 10:06:32 

à¤®à¥‹à¤¹à¤¨:
20150206 11:51:34
Here comes a my 100th!!! :) 

Saksham :
20150109 13:19:16
a very good indeed


bourne:
20141215 10:15:38
I think @Rahul Jain is correct. Not satisfying for S=0. Although the proof is easy for other values of S. Ignore the pattern and Try it :) ! 

Vamsi Krishna Avula:
20141215 07:28:22
I was not able to prove it mathematically but observing the pattern was easy enough. 

NEXES:
20141129 18:42:26
AC in one go.....

Added by:  AvmnuSng 
Date:  20140614 
Time limit:  0.119s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Abhimanyu Singh My Problems 