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.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;

public class Main {
    private static AWriter writer = new AWriter(System.out);
    private static AReader reader = new AReader(System.in);
    private static final int INF=0X3F3F3F3F;
    private static int MAXN=6000+5;
    private static int MAXM=4000+5;
    private static int N,s,t;
    private static int[] dis;
    private static int[] head;
    private static boolean[] vis;
    private static int[] lev;
    private static int tot;
    private static Edge[][] edges;
    static class Edge{
        int flow,cap;
        public Edge() {
            this.flow = 0;
            this.cap = 0;
        }
    }
    private static int dfs(int s,int t,int flow){
        if(s==t)
            return flow;
        int now=flow;
        for(int i=0;i<N;i++){
            if(lev[i]==lev[s]+1&&edges[s][i].cap>edges[s][i].flow){
                int min=Math.min(now,edges[s][i].cap-edges[s][i].flow);
                int nowFlow=dfs(i,t,min);
                edges[s][i].flow+=nowFlow;
                edges[i][s].flow-=nowFlow;
                now-=nowFlow;
            }
            if(now==0)
                break;
        }
        return flow-now;
    }
    private static boolean bfs(int s,int t){
        lev=new int[MAXN];
        Queue<Integer> queue=new LinkedBlockingQueue<>();
        queue.add(s);
        lev[s]=1;
        while(!queue.isEmpty()){
            int u=queue.poll();
            for(int i=0;i<N;i++){
                if(lev[i]==0&&edges[u][i].cap>edges[u][i].flow){
                    lev[i]=lev[u]+1;
                    queue.add(i);
                }
            }
        }
        return lev[t]!=0;
    }
    private static void dinic(int s,int t){
        int flow=0,tf=0;
        while(bfs(s,t)){
            while((tf=dfs(s,t,INF))!=0){
                flow+=tf;
            }
        }
    }
    private static boolean[] vi;
    private static int[] a;
    private static List<Long> list,sum;
    private static final double eps=10e-8;
    private static long m,n;
    public static void main(String[] args) throws IOException {
        int T=reader.nextInt();
        while(T--!=0) {
            n=reader.nextLong();
            m=reader.nextLong();
            long tmp=m;
            long num=n/m;
            sum=new ArrayList<>();
            list=new ArrayList<>();
            sum.add(0l);
            while(tmp%10!=0) {
                list.add(tmp%10);
                tmp%=10;
                tmp+=m;
            }
            for(int i=0;i<list.size();i++)
                sum.add(sum.get(i)+list.get(i));
            long ans=(num/(list.size()+1))*sum.get(list.size());
            long mo=num%(list.size()+1);
            ans+=sum.get((int)mo);
            writer.println(ans);
        }
        writer.close();
        reader.close();
    }
}

class AReader implements Closeable {
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    public AReader(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }
    private String innerNextLine() {
        try {
            return reader.readLine();
        } catch (IOException ex) {
            return null;
        }
    }
    public boolean hasNext() {
        while (!tokenizer.hasMoreTokens()) {
            String nextLine = innerNextLine();
            if (nextLine == null) {
                return false;
            }
            tokenizer = new StringTokenizer(nextLine);
        }
        return true;
    }
    public String nextLine() {
        tokenizer = new StringTokenizer("");
        return innerNextLine();
    }
    public String next() {
        hasNext();
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.valueOf(next());
    }
    public long nextLong() {
        return Long.valueOf(next());
    }
    public double nextDouble() {
        return Double.valueOf(next());
    }
    public BigDecimal nextBigDecimal(){ return new BigDecimal(next()); }
    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
    @Override
    public void close() throws IOException {
        reader.close();
    }
}

// Fast writer for ACM By Azure99
class AWriter implements Closeable {
    private BufferedWriter writer;

    public AWriter(OutputStream outputStream) {
        writer = new BufferedWriter(new OutputStreamWriter(outputStream));
    }

    public void print(Object object) throws IOException {
        writer.write(object.toString());
    }

    public void println(Object object) throws IOException {
        writer.write(object.toString());
        writer.write("\n");
    }

    @Override
    public void close() throws IOException {
        writer.close();
    }
}