t = int(input())
while t:
    t = t - 1
    n,m = map(int,input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
        
    f = 0
    res = 0
    for i in a:
        if i in b:
            res = i
            f = 1
            break;
    
    if f == 0:
        print("NO")
    else:
        print("YES")
        print(1, res)