Pravin ,Saddam and their Aptitude question

3.1

29 votes
Problem

Pravin and Saddam are room-mates.They always solve aptitude questions together. Once, they came across a problem stated as:

"Find the digit at the unit place that appears in sum of factorials of all numbers between A and B (both inclusive)."

Though they are good at mathematics ,but this time they are scratching their heads due to computation of factorials. They seek help from you. Your job is to help them by writing a code for them to solve their problem.

Input:

First line contains a number T (number of test cases).

Next T lines contains two numbers A and B.

Output:

Print T lines of output where each line contains the required answer.

Constraints:

1<=T<=100

1<= A<=B <=18

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Test case #1:

1! + 2!

=1 + 2=03

unit place =3

Test case#2:

3! + 4! + 5!

= 6 + 24 + 120= 150

unit place =0

Editor Image

?