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<=10^{18}

**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
```

Author: arun03

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

agness | 122 |

aman1931998 | 102 |

Survivor | 100 |

uchitnitk | 96 |

lonecoder | 95 |

KshatriyaYash | 1066 |

nikhil_sojan | 1032 |

lonecoder | 1030 |

mazumderrohit8 | 899 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4492 |

Quandray | 4444 |

Login to report an issue on this page.