#codeforces round 658 div 2
import sys
def input():
    return sys.stdin.readline()[:-1]
def getInt():
    return int(input())
def getIntIter():
    return map(int, input().split())
def getIntList():
    return list(getIntIter())

for _ in range(getInt()):
    n,m = getIntIter()
    a = getIntList()
    b = getIntList()
    for item in a:
        if item in b:
            print("YES")
            print(1,item)
            break
    else:
        print("NO")
