for _ in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    a.sort()
    b.sort()
    ans = list(set(a) & set(b))
    if len(ans) > 0:
        print('YES')
    else:
        print("NO")
        continue
    print(1,' ',ans[0])