for _ in range(int(input())):
    n, m = map(int, input().split())
    a = set(map(int,input().split()))
    b = map(int,input().split())

    found, ans = False, -1
    for x in b:
        if x in a:
            found = True
            ans = x
            break
    
    if found: 
        print('YES')
        print(1,ans)
    else: print('NO')
