Find the last digit when factorial of A divides factorial of B
Medium Accuracy: 31.45% Submissions: 1694 Points: 4

Given two numbers A and B. The task is to compute the last digit of the resulting F, where F= B! / A! .

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains two number A and B as input.

Output:
For each test case, print last digit of B! / A! (B factorial/ A factorial).

Constraints:
1<=T<=100
1<=A<=B<=1018

Example:
Input:
2

2 4
107 109

Output:
2
2

Explanation:

Input : A = 2, B = 4
Output : 2
Explanation : A! = 2 and B! = 24.
F = 24/2 = 12 --> last digit = 2

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?