t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    find = False
    for a_v in a:
        if a_v in b:
            print(f'YES\n1 {a_v}')
            find = True
            break

    if not find:
        print('No')
