for _ in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    res = list()
    if len(a)<=len(b):
        for i in a:
            if i in b:
                res.append(i)
                break
    else:
        for i in b:
            if i in a:
                res.append(i)
                break
    if res:
        print('YES')
        print(len(res), *res)
    else:
        print('NO')