for _ in range(int(input())):
    n, m = map(int, input().split())
    s = list(map(int, input().split()))
    m = list(map(int, input().split()))
    p = 1
    for i in range(n):
        if s[i] in m:
            p = 0
            print('YES')
            print(1, s[i])
            break
    if p == 1:
        print('NO')