for _ in range(int(input())):
    n, m = map(int, input().split())
    str1 = [int(x) for x in input().split()]
    str2 = [int(x) for x in input().split()]
    flag = True
    for num in str1:
        if num in str2:
            print("YES")
            print(1, num)
            flag = False
            break
    if flag: print("NO")