import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.net.ssl.SSLContext;

public class Main
{	
   static HashMap<Integer,Integer> index;static int g=0; static int l=0;
   
   public static int lower_bound(int start,int end,int a[],int key)
   {
	   if(start>end) return start;
	   int mid=(start+end)>>1;
	   
	   if(a[mid]==key) return mid;
	   
	   if(key<a[mid]) return lower_bound(start,mid-1,a,key);
	   else return lower_bound(mid+1,end,a,key);  
   }
   
   public static void main(String[] args) throws java.lang.Exception
   {	  	 

	     fast s = new fast();
	     PrintWriter out=new PrintWriter(System.out);
	     StringBuilder final_ans = new StringBuilder();
	     
	     int t=s.nextInt();
	     
	     while(t!=0)
	     {
	    	 int n=s.nextInt();
	    	 int st=s.nextInt();
	    	 index=new HashMap<Integer,Integer>();
	    	 
	    	 int a[]=new int[n];
	    	 int b[]=new int[st];    	 
	    	 int temp[]=new int[n];
	    	 
	    	 for(int i=0;i<n;i++) {a[i]=s.nextInt();temp[i]=a[i];index.put(a[i], i);}
	    	 for(int i=0;i<st;i++) b[i]=s.nextInt();
	    	 
    		 Arrays.sort(temp);
	    	 for(int i=0;i<st;i++)
	    	 {
	    		 l=0; g=0;
	    		 int pos=index.get(b[i]);
	    		 
	    		 int low=0; int high=n-1;
	    		 
	    		 while(low<=high)
	    		 {
	    			 int mid=(low+high)>>1;
                       
	    		     if(mid==pos) break;
	    		     
	    		     if(mid<pos)
	    		     {
	    		    	 if(a[mid]>b[i]) g++;
	    		    	 low=mid+1;
	    		     }
	    		     else if(mid>pos)
	    		     {
	    		    	 if(a[mid]<b[i]) l++;
	    		    	 high=mid-1;
	    		     }	    		 
	    		 }
	    		 
	    		 int lb=lower_bound(0,n-1,temp,b[i]);
	    		 int gb=n-1-lb;

	    		 if(l==g) System.out.println(l);
	    		 else if(l>g)
	    		 {
	    			 if(gb<l) System.out.println("-1");
	    			 else System.out.println(l);
	    				 
	    		 }
	    		 else
	    		 {
	    			 if(lb<g) System.out.println("-1");
	    			 else System.out.println(g);
	    		 }	    	   
	    	 }
	    	 
	    	 t--;
	     }
  
   }

   static class fast {
		private InputStream i;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		
		public int gcd(int a,int b)
		{
			if(a==0) return b;
			return gcd(b%a,b);
		}
		public fast() {
			this(System.in);
		}
		public fast(InputStream is) {
			i = is;
		}
		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = i.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
		public String nextString() {
     		int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}	
}
       
 
   
 



