/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int n,q,t,i,j,maxi=-1;
t=sc.nextInt(); //error refers here
for(i=1;i<=t;i++)
{
n=sc.nextInt();
q=sc.nextInt();
int[] narr=new int[100000];
int[] qarr=new int[100000];
int[] ans=new int[100000];
for(j=0;j<n;j++)
{
narr[j]=sc.nextInt();
ans[j]=Math.max(narr[j],maxi);
if(narr[j]>maxi)
maxi=narr[j];
}
for(j=0;j<q;j++)
{
qarr[j]=sc.nextInt();
System.out.println(ans[qarr[j]-1]);
}
maxi=-1;
}
}
}