1
2 2
1 1
1 2
 1
1 3
3
1 2 3
 1
1 1
1000
1000
 1
2 2
2 2
2 2
 5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5
 1
4 4
1 1 1 1
1 2 3 4
 1
2 3
1 1
1 2 3

YES
1 1
 YES
1 3
 YES
1 1000
 YES
1 2
 YES
1 4
YES
1 3
NO
YES
1 3
YES
1 1
 YES
1 1
 YES
1 1

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:
                print("YES")
                print("1",key)
                return
        print("NO")

    if __name__ == "__main__":
        main()

except Exception:
    pass
