Suppose you are performing the following algorithm. There is an array v_1, v_2, ..., v_n filled with zeroes at start. The following operation is applied to the array several times — at i-th step (0-indexed) you can: 

  * either choose position pos (1 ≤ pos ≤ n) and increase v_{pos} by k^i; 
  * or not choose any position and skip this step. 



You can choose how the algorithm would behave on each step and when to stop it. The question is: can you make array v equal to the given array a (v_j = a_j for each j) after some step?

Input

The first line contains one integer T (1 ≤ T ≤ 1000) — the number of test cases. Next 2T lines contain test cases — two lines per test case.

The first line of each test case contains two integers n and k (1 ≤ n ≤ 30, 2 ≤ k ≤ 100) — the size of arrays v and a and value k used in the algorithm.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^{16}) — the array you'd like to achieve.

Output

For each test case print YES (case insensitive) if you can achieve the array a after some step or NO (case insensitive) otherwise.

Example

Input


5
4 100
0 0 0 0
1 2
1
3 4
1 4 1
3 2
0 1 3
3 9
0 59049 810


Output


YES
YES
NO
NO
YES

Note

In the first test case, you can stop the algorithm before the 0-th step, or don't choose any position several times and stop the algorithm.

In the second test case, you can add k^0 to v_1 and stop the algorithm.

In the third test case, you can't make two 1 in the array v.

In the fifth test case, you can skip 9^0 and 9^1, then add 9^2 and 9^3 to v_3, skip 9^4 and finally, add 9^5 to v_2.
import java.io.*;
import java.util.*;

public class Q1 {


    public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);

        int t =in.nextInt();
        while(t-->0) {
            int N = in.nextInt(),M=in.nextInt();
            long arr[] = new long[N];
            ArrayList<Long> pow=new ArrayList<>();
            pow.add(1l);
            for(int i =1;i<64;i++){
                long num=pow.get(pow.size()-1)*M;
                if(num>0)
                    pow.add(num);
                else
                    break;
            }
            int flag=1; HashSet<Integer>set=new HashSet<>();
            for(int  i=0;i<N;i++){
                arr[i]=in.nextLong();
                for(int j=pow.size()-1;j>=0;j--){
                    long d=pow.get(j);
                    if(d>arr[i])
                        continue;
                    long num=arr[i]/d,rem=arr[i]%d;
                    if(num>1)
                        flag=-1;
                    arr[i]=rem;
                    if(set.contains(j))
                        flag=-1;
                    set.add(j);
                }
            }

            if(flag==-1)
            out.println("NO");
            else
                out.println("YES");
        }
        out.close();
    }


// ternary Search Question
//    public static void main(String[] args) {
//
//        InputReader in = new InputReader();
//        PrintWriter out = new PrintWriter(System.out);
//        int t=in.nextInt();
//        while(t-->0) {
//
//            int N = in.nextInt(),max=-1,diff=0;
//            int arr[] = new int[N];
//            for(int  i=0;i<N;i++){
//                arr[i]=in.nextInt();
//                max=Math.max(max,arr[i]);
//            }
//            if(max==-1){
//                out.println(0+" "+1);
//                continue;
//            }
//
//
//
//            for(int i =1;i<N;i++){
//                int  a =arr[i]==-1?max:arr[i],b =arr[i-1]==-1?max:arr[i-1],d=Math.abs(a-b);
//                diff=Math.max(diff,d);
//            }
//            System.out.println(max+"  diff:-"+diff);
//
//            int l=0,r=max;
//            while(l<=r){
//                int mid=(l+r)/2;
//                int di=0;
//                for(int i =1;i<N;i++){
//                    int  a =arr[i]==-1?mid:arr[i],b =arr[i-1]==-1?mid:arr[i-1],d=Math.abs(a-b);
//                    di=Math.max(di,d);
//                }
//                System.out.println(mid+"  diff:-"+di);
//                if(di<diff){
//                    r=mid-1;
//                    max=mid; diff=di;
//                }else{
//                    l=mid+1;
//                }
//            }
//
//            out.println(diff+" "+max);
//
//        }
//        out.close();
//
//
//    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public int[] shuffle(int[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                arr[i] = arr[i] ^ arr[j];
                arr[j] = arr[i] ^ arr[j];
                arr[i] = arr[i] ^ arr[j];
            }
            return arr;
        }

        public InputReader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public char nextChar() {
            return next().charAt(0);
        }

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

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

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


    }

}


//    public static void main(String[] args) {
//
//        InputReader in = new InputReader();
//        PrintWriter out = new PrintWriter(System.out);
//        int t  =in.nextInt();
//
//        while(t-->0){
//            int  N=in.nextInt();
//            int arr[]=new int[N];
//            for(int i=0 ;i<N;i++)
//                arr[i]=in.nextInt();
//
//            ArrayList<Integer> set1=new ArrayList<>(),set2=new ArrayList<>(),set3=new ArrayList<>();
//            double xval=in.nextInt(),x=in.nextInt(),yval=in.nextInt(),y=in.nextInt();
//            long k=in.nextLong();
//            long  ans  =0;
//
//            if(xval<yval){
//                double temp=xval;
//                xval=yval;
//                yval=temp;
//
//                temp=x;
//                x=y;
//                y=temp;
//            }
//            xval=xval/100; yval=yval/100;
//
//            for(int i =0;i<N;i++){
//                if((i+1)%x==0 && (i+1)%y==0)
//                    set1.add(i);
//                else if ((i+1)%x==0 )
//                    set2.add(i);
//                else if((i+1)%y==0)
//                    set3.add(i);
//            }
//            arr=in.shuffle(arr);
//
//            int a =0,b=0,c=0,add=0;
//
//            for(int  i=N-1;i>=0;i--){
//
//                int temp=0;
//
//                if(a==set1.size()  && b==set2.size()  && c==set3.size())
//                    continue;
//                else if (a==set1.size()  && b==set2.size() ){
//                    ans += (yval) * arr[i];
//                    c++;
//                    temp=11;
//                }else if(a==set1.size()){
//                    if (set2.get(b) <set3.get(c)) {
//                        ans += (xval) * arr[i];
//                        b++;
//                    } else {
//                        ans += (yval) * arr[i];
//                        c++;
//                    }
//                }else{
//                    if (set1.get(a) < set2.get(b) && set1.get(a) < set3.get(c)) {
//                        ans += (xval + yval) * arr[i];
//                        a++;
//                    } else if (set2.get(b)<set3.get(c)) {
//                        ans += (xval) * arr[i];
//                        b++;
//                    } else {
//                        ans += (yval) * arr[i];
//                        c--;
//                    }
//                }
//
//
//
//                if(ans>=k){
//                    break;
//                }
//
//            }
//
//            if(ans<k)
//                out.println(-1);
//            else
//                out.println(add);
//
//
//
//        }
//
//        out.close();
//    }


//
//import java.io.*;
//import java.util.*;
//
//
//public class Q3 {
//
//
//    // tunnel wala Question tourist
//
////    public static void main(String[] args) {
////
////        InputReader in = new InputReader();
////        PrintWriter out = new PrintWriter(System.out);
////
////        int  N=in.nextInt();
////        int arr1[]=new int [N],arr2[]=new int[N];
////        int ans =0;
////
////        for(int i =0;i<N;i++){
////            arr1[i]=in.nextInt();
////        }
////
////        HashMap<Integer,Integer>map=new HashMap<>();
////
////        for(int j=0;j<N;j++){
////            int num=in.nextInt();
////            arr2[j]=num;
////            map.put(num,N-j);
////        }
////        int a[]=new int [N+1];
////
////        boolean flag=false;
////        for(int i =0;i<N;i++) {
////            int num = arr1[i];
////            int val=map.get(num);
////            if(val>(N-i))
////                ans++;
////            else if(val==N-i && !flag){
////                ans++;
////
////            }
////            a[arr1[i]]++;
////            a[arr2[N-i-1]]++;
////
////            if(a[arr1[i]]!=2 || a[arr2[N-i-1]]!=2)
////                flag=false;
////            else
////                flag=true;
////
////        }
////        out.println(ans);
////
////        out.close();
////
////
////    }
//
//    static class InputReader {
//        public BufferedReader reader;
//        public StringTokenizer tokenizer;
//
//
//        public int[] shuffle(int[] arr) {
//            Random r = new Random();
//            for (int i = 1, j; i < arr.length; i++) {
//                j = r.nextInt(i);
//                arr[i] = arr[i] ^ arr[j];
//                arr[j] = arr[i] ^ arr[j];
//                arr[i] = arr[i] ^ arr[j];
//            }
//            return arr;
//        }
//
//        public InputReader() {
//            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
//            tokenizer = null;
//        }
//
//        public InputReader(InputStream stream) {
//            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
//            tokenizer = null;
//        }
//
//        public String next() {
//            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
//                try {
//                    tokenizer = new StringTokenizer(reader.readLine());
//                } catch (IOException e) {
//                    throw new RuntimeException(e);
//                }
//            }
//            return tokenizer.nextToken();
//        }
//
//        public char nextChar() {
//            return next().charAt(0);
//        }
//
//        public int nextInt() {
//            return Integer.parseInt(next());
//        }
//
//        public long nextLong() {
//            return Long.parseLong(next());
//        }
//
//        public double nextDouble() {
//            return Double.parseDouble(next());
//        }
//
//
//    }
//
//}