t = int(input())
for x in range(t):
    n, m = map(int, input().split())
    na = list(map(int, input().split()))
    ma = list(map(int, input().split()))
    if n>m:
        a = ma
        b = na
    else:
        a = na
        b = ma
    for y in range(len(a)):
        if a[y] in b:
            print("YES")
            print(1, a[y])
            break
    else:
        print("NO")