import java.math.BigInteger;
import java.util.Scanner;
public class test4 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
for (int j = 0; j < n; j++) {
int n1=sc.nextInt();
int n2=sc.nextInt();
BigInteger bg = new BigInteger(“1”);
BigInteger bg2 = new BigInteger(“1”);
for (int i = 0; i < n1; i++) {
int t1=sc.nextInt();
bg=bg.multiply(new BigInteger(String.valueOf(t1)));
}
for (int i = 0; i < n2; i++) {
int t2 = sc.nextInt();
bg2=bg2.multiply(new BigInteger(String.valueOf(t2)));
}
if(bg.mod(bg2).equals(new BigInteger(“0”))){
System.out.println(“yes”);
}else {
System.out.println(“no”);
}
}
}
}