import sys
input = sys.stdin.readline
for _ in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = {i: True for i in map(int,input().split())}
    ans = 'NO'
    for i in a:
        if(i in b):
            ans = 'YES'
            print(ans)
            print('1',i)
            break
    if(ans=='NO'):
        print(ans)