Upcoming Connoisseur

1

1 votes
Problem

Chef has been in the culinary business for a long time now and with this experience, he wants to expand his profile to a professional food critic. He has been tasting various food items from different cuisines, grading them points and posting them on his blog. The blog is thriving and is gaining a lot of followers who want to take Chef’s recommendation and try out the dishes on their own.

Chef wants to create a paid program to help his readers taste the dishes but he is busy updating his blog so he wants your help.

You are given N dishes, each with base price A and score B. The cost of each food item is the ending digit of AB. Yes, the dishes are cheap, the chef is a real people’s man!

You have to answer Q queries. Each query has a starting index L and an ending index R. In each query you have to determine the total cost of the dishes from L to R (inclusive).

INPUT :

  • The first line of each test case contains N, the number of dishes
  • N lines follow which contain two space-separated integers A and B, the base price and the score, respectively.
  • The next line contains Q, the number of queries.
  • Q lines follow which contain two space-separated integers L and R, the starting and ending indices, respectively.

OUTPUT :

                For each query print the total cost of the dishes from L to R (inclusive) in a new line.

CONSTRAINTS :

  • 1 <= N <= 105
  • 0 <= A <= 109
  • 1 <= B <= 1010
  • 1 <= Q <=105
  • 1 <= L <= R <= N
Sample Input
3
2 2
3 2
4 1
2
1 2
2 3
Sample Output
13
13
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The cost of the dishes is 4, 9 and 4, respectively. Query 1 is 4+9 that is 13. Similarly, Query 2 is 9+4 that is 13.

Editor Image

?