__MULTITEST = True

## solve
def solve():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    for x in a:
        try:
            v = b.index(x)
            print("YES")
            print(1, x)
            return
        except:
            pass
    
    print("NO")

## main
if __name__ == "__main__":
    t = (int(input()) if __MULTITEST else 1)
    for tt in range(t):
        solve();