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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;

import java.util.HashMap;

import java.util.StringTokenizer;



public class Main {

   public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

   static class FastReader {

     BufferedReader br;
     StringTokenizer st;

     public FastReader() {
       br = new BufferedReader(new
           InputStreamReader(System.in));
     }

     String next() {
       while (st == null || !st.hasMoreElements()) {
         try {
           st = new StringTokenizer(br.readLine());
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
       return st.nextToken();
     }

     int nextInt() {
       return Integer.parseInt(next());
     }

     long nextLong() {
       return Long.parseLong(next());
     }

     double nextDouble() {
       return Double.parseDouble(next());
     }

     String[] nextSArray() {
       String sr[] = null;
       try {
         sr = br.readLine().trim().split(" ");
       } catch (IOException e) {
         e.printStackTrace();
       }
       return sr;
     }

     String nextLine() {
       String str = "";
       try {
         str = br.readLine();
       } catch (IOException e) {
         e.printStackTrace();
       }

       return str;
     }
   }

   //  static int MOD=1000000000+7;
//  public static void sortbyCol(int arr[][],int col)
//  {
//    Arrays.sort(arr,new Comparator<int[]>(){
//      @Override
//      public int compare(int[] o1, int[] o2) {
//        // To sort in descending order revert
//        // the '>' Operator
//        if(o1[col]>o2[col])
//          return 1;
//        else
//          return -1;
//      }
//    });
//  }
//   static int countbits(int a) {
//     if (a == 0)
//       return 0;
//     return (int) (Math.log(a) / Math.log(2) + 1);
//   }

//  static long[][] Multiply(long[][] a,long[][] b)
//  {
//    int i, j, k;
//    int N=a.length;
//    long res[][]=new long[N][N];
//    for (i = 0; i < N; i++)
//    {
//      for (j = 0; j < N; j++)
//      {
//        res[i][j] = 0;
//        for (k = 0; k < N; k++)
//          res[i][j] =(res[i][j]+( a[i][k] * b[k][j])%mod)%mod;
//      }
//    }
//    return res;
//  }

//  static long[][] FastPower(long[][] tran,long pow)
//  {
//      if(pow==1)
//        return tran;
//      long temp[][]=FastPower(tran,pow/2);
//      if(pow%2==0)
//       return tran=Multiply(temp,temp);
//      else
//      return tran=Multiply(tran,Multiply(temp,temp));
//
//  }
//
//  static long gcd(long a,long b)
//  {
//    if(a==0)
//      return b;
//    return  gcd(b%a,a);
//  }

static long mod=1000000007;
   public static void main(String[] args) throws java.lang.Exception {
    FastReader sc = new FastReader();
//     HashMap<Integer,Integer>hm=new HashMap<>();
//     for(int i=1;i<=9;++i)
//     {
//       int sum=0;
//       int num=i;
//       for(int j=1;j<10;++j)
//       {
//         sum+=(i*j)%10;
//
//       }
//       hm.put(i,sum);
//     }
//     for (Integer k : hm.keySet()) {
//       System.out.println(k+" "+hm.get(k));
//     }

    int t1=sc.nextInt();
    for(int t=0;t<t1;++t)
    {
      long n=sc.nextLong();
      long m=sc.nextLong();
      int lastdigit=(int) (m%10);
      long lastsum=0;
      if(lastdigit==5)
        lastsum=25;
      else if(lastdigit==0)
        lastsum=0;
      else if(lastdigit%2==0)
        lastsum=40;
      else if(lastdigit%2==1)
        lastsum=45;

      long div=n/m;
      int mod=(int)(div%10);
      div=div/10;
      long ans=div*lastsum;
     // System.out.println(ans);
      for(int i=1;i<=mod;++i)
      {
        ans+=(lastdigit*i)%10;
      }
      out.println(ans);
    }


   out.flush();
   out.close();
   }
 }



// out.println(al.toString().replaceAll("[\\[|\\]|,]",""));

