try:
    from collections import Counter
    from sys import stdin, stdout
    def get_ints(): return map(int, stdin.readline().strip().split())
    def get_list(): return list(map(int, stdin.readline().strip().split()))
    def get_string(): return stdin.readline().strip()
    def get_singleInt(): return int(stdin.readline())
    def main():
        testCases=get_singleInt()
        for i in range(testCases):
            n,m=get_ints()
            arrayN=get_list()
            arrayM=get_list()
            minCommonSubSequence(n,m,arrayN,arrayM)

    def minCommonSubSequence(n,m,arrayN,arrayM):
        counterN=Counter(arrayN)
        counterM=Counter(arrayM)
        for key in counterN:
            if key in counterM:
                stdout.write(str("YES")+"\n")
                stdout.write(str("1")+" ")
                stdout.write(str(key)+"\n")
                return
        stdout.write(str("NO")+"\n")

    if __name__ == "__main__":
        main()

except Exception:
    pass
