Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly n flowers.

Vladimir went to a flower shop, and he was amazed to see that there are m types of flowers being sold there, and there is unlimited supply of flowers of each type. Vladimir wants to choose flowers to maximize the happiness of his wife. He knows that after receiving the first flower of the i-th type happiness of his wife increases by a_i and after receiving each consecutive flower of this type her happiness increases by b_i. That is, if among the chosen flowers there are x_i > 0 flowers of type i, his wife gets a_i + (x_i - 1) ⋅ b_i additional happiness (and if there are no flowers of type i, she gets nothing for this particular type).

Please help Vladimir to choose exactly n flowers to maximize the total happiness of his wife.

Input

The first line contains the only integer t (1 ≤ t ≤ 10 000), the number of test cases. It is followed by t descriptions of the test cases.

Each test case description starts with two integers n and m (1 ≤ n ≤ 10^9, 1 ≤ m ≤ 100 000), the number of flowers Vladimir needs to choose and the number of types of available flowers.

The following m lines describe the types of flowers: each line contains integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^9) for i-th available type of flowers.

The test cases are separated by a blank line. It is guaranteed that the sum of values m among all test cases does not exceed 100 000.

Output

For each test case output a single integer: the maximum total happiness of Vladimir's wife after choosing exactly n flowers optimally.

Example

Input


2
4 3
5 0
1 4
2 2

5 3
5 2
4 2
3 1


Output


14
16

Note

In the first example case Vladimir can pick 1 flower of the first type and 3 flowers of the second type, in this case the total happiness equals 5 + (1 + 2 ⋅ 4) = 14.

In the second example Vladimir can pick 2 flowers of the first type, 2 flowers of the second type, and 1 flower of the third type, in this case the total happiness equals (5 + 1 ⋅ 2) + (4 + 1 ⋅ 2) + 3 = 16.
import java.util.*;
import java.io.*;
public class Main implements Runnable{
    FastScanner sc;
    PrintWriter pw;
    final class FastScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
        public long nlo() {
            return Long.parseLong(next());
        }
 
        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }
 
        public int ni() {
            return Integer.parseInt(next());
        }
 
        public String nli() {
            String line = "";
            if (st.hasMoreTokens()) line = st.nextToken();
            else try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            while (st.hasMoreTokens()) line += " " + st.nextToken();
            return line;
        }
 
        public double nd() {
            return Double.parseDouble(next());
        }
    }
    public static void main(String[] args) throws Exception
    {
        new Thread(null,new Main(),"codeforces",1<<28).start();
    }
    public void run()
    {
        sc=new FastScanner();
        pw=new PrintWriter(System.out);
        solve();
        pw.flush();
        pw.close();
    }
    public long gcd(long a,long b)
    {
        return b==0L?a:gcd(b,a%b);
    }
    public long ppow(long a,long b,long mod)
    {
        if(b==0L)
        return 1L;
        long tmp=1;
        while(b>1L)
        {
            if((b&1L)==1)
            tmp*=a;
            a*=a;
            a%=mod;
            tmp%=mod;
            b>>=1;
        }
        return (tmp*a)%mod;
    }
    public  int gcd(int x,int y)
    {
        return y==0?x:gcd(y,x%y);
    }
    public class Pair implements Comparable<Pair>{
        int x;
        int val;
        Pair(int a,int b)
        {
            x=a;
            val=b;
        }
        public int compareTo(Pair b)
        {
            return this.val-b.val;
        }
        public Pair clone(Pair b)
        {
            return new Pair(b.x,b.val);
        }
    }
    //////////////////////////////////
    /////////////  LOGIC  ///////////
    ////////////////////////////////
    class Node implements Comparable<Node>{
        long x;
        long y;
        Node(long a,long b)
        {
            x=a;
            y=b;
        }
        public int compareTo(Node b)
        {
            if(x<b.x)
            return -1;
            else if(x>b.x)
            return 1;
            return 0;
        }
    }
    public void solve() {
        int t=sc.ni();
        while(t-->0)
        {
            long req=sc.ni();
            int m=sc.ni();
            ArrayList<Node> list=new ArrayList<>();
            for(int i=0;i<m;i++)
              list.add(new Node(sc.ni(),sc.ni()));
              
              int n=m;
              long[] arr=new long[n];
              long[] brr=new long[n];
              Collections.sort(list);
              for(int i=0;i<n;i++)
              {
                  arr[i]=list.get(i).x;
                  brr[i]=list.get(i).y;
              }
              int x;
              long[] srr=new long[n];
              srr[n-1]=arr[n-1];
              for(int i=n-2;i>=0;i--)
              srr[i]=arr[i]+srr[i+1];
              long ans=arr[n-1]+(req-1l)*brr[n-1];
              for(int i=0;i<n;i++)
              {
                x=bs(arr,0,n-1,brr[i]);
                //  pw.println(arr[i]+" "+brr[i]+ " "+x);
                  if(x==-1)
                    ans=Math.max(ans,arr[i]+(req-1L)*brr[i]);
                 else
                 {
                     long l=n-x;
                     if(l>=req)
                        ans=Math.max(ans,srr[n-(int)req]);
                     else
                     {
                        l=req-l;
                        if(x>i)
                        ans=Math.max(ans,arr[i]+(l-1L)*brr[i]+srr[x]);
                        else
                        ans=Math.max(ans,(l)*brr[i]+srr[x]);
                     }
                 }
              }
              pw.println(ans);
            sc.nli();
        }
    }
    public int bs(long[] arr,int s,int e,long val)
    {
        if(s>e||arr[e]<val)
        return -1;
        int ans=e;
        while(s<=e)
        {
            int m=(s+e)/2;
            if(arr[m]>=val)
            {
                e=m-1;
                ans=m;
            }
            else
            s=m+1;
        }
        return ans;
    }
}