Polycarp is reading a book consisting of n pages numbered from 1 to n. Every time he finishes the page with the number divisible by m, he writes down the last digit of this page number. For example, if n=15 and m=5, pages divisible by m are 5, 10, 15. Their last digits are 5, 0, 5 correspondingly, their sum is 10.

Your task is to calculate the sum of all digits Polycarp has written down.

You have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries.

The following q lines contain queries, one per line. Each query is given as two integers n and m (1 ≤ n, m ≤ 10^{16}) — the number of pages in the book and required divisor, respectively.

Output

For each query print the answer for it — the sum of digits written down by Polycarp.

Example

Input


7
1 1
10 1
100 3
1024 14
998244353 1337
123 144
1234312817382646 13


Output


1
45
153
294
3359835
0
427262129093995
import java.io.*;
import java.util.*;
import java.util.Map.Entry;

public class abc {

	public static void main(String[] args) throws NumberFormatException, IOException {
/*		 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    	 int n=Integer.parseInt(br.readLine());
	    	 int[] arr=new int[n];
	    	 String[] ss=br.readLine().trim().split(" ");
	    	 int maxFreq=0,max=Integer.MIN_VALUE;
	    	 HashMap<Integer,Integer> map=new HashMap<>();
	    	 
	    	 for(int i=0 ; i<arr.length ; i++){
	    	    arr[i]=Integer.parseInt(ss[i]);
	    	    if(map.containsKey(arr[i])) {
	    	    	map.put(arr[i],map.get(arr[i])+1);
	    	    }else {
	    	    	map.put(arr[i],1);
	    	    }
	    	    if(map.get(arr[i])>maxFreq) {
	    	    	max=arr[i];
	    	    	maxFreq=map.get(arr[i]);
	    	    }
	    	  }
	    	 Arrays.sort(arr);
	    	 helper(arr,max);
*/
		
/*		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		 int w=Integer.parseInt(br.readLine());
		 while(w-->0){
	    	 int n=Integer.parseInt(br.readLine());
	    	 int[] arr=new int[n];
	    	 String[] ss=br.readLine().trim().split(" ");
	    	 for(int i=0 ; i<arr.length ; i++){
	    	    arr[i]=Integer.parseInt(ss[i]);
	    	    }
	         int[] rightMin=new int[n];
	         int min=Integer.MAX_VALUE;
	         for(int i=arr.length-1 ; i>=0 ; i--) {
	        	 min=Math.min(arr[i],min);
	        	 rightMin[i]=min;
	         }
	         int count=0;
	         for(int i=0 ; i<arr.length-1 ; i++) {
	        	 if(arr[i]>rightMin[i+1]) {
	        		 count++;
	        	 }
	         }
	         System.out.println(count);

		
	    }
*/
		
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		 int w=Integer.parseInt(br.readLine());
		 while(w-->0){
			 String[] ss=br.readLine().trim().split(" ");
	    	 long n=Long.parseLong(ss[0]);
	    	 long k=Long.parseLong(ss[1]);
			long sum=0;
			long a=k;
			long i=0;
			int count=0;
			for(i=k ; i<=n ; i+=k) {
				sum=sum+(i%10);
				count++;
				if(count%10==0) {
					break;
				}
			}
			
			long f=(n)/(k*10);
			long r=n-(f*k*10);
			sum=sum*f;
			for(i=0 ; i<=r ; i+=k) {
				sum=sum+(i%10);
			}
			System.out.println(sum);
			 }
	}
	
	
	public static void helper(int[] arr , int max) {
   	 int count=0,min=Integer.MAX_VALUE;
   	 max=arr[(arr.length/2)];
   	 
       for(int i=0 ; i<arr.length ; i++) {
       	if((Math.abs(max-arr[i]))%2!=0) {
       		count++;
       	}
       }
       int count2=0;
       max=arr[(arr.length+1)/2];
       for(int i=0 ; i<arr.length ; i++) {
       	if((Math.abs(max-arr[i]))%2!=0) {
       		count2++;
       	}
       }
       min=Math.min(count, count2);
   	 System.out.println(min);
	}
}