'''
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
'''
for _ in range(int(input())):
    lena, lenb = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    found = False
    for i in a:
        if i in b:
            print("YES")
            print (1, i)
            found = True
            break
    if not found:
        print("NO")
        
            
        