t = int(input())




def main():
    n, m = [int(x) for x in input().split(' ')]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    for i in range(len(a)):
        try:
            result = b.index(a[i])
        except:
            result = None
        if result is not None:
            print('YES')
            print(f'1 {a[i]}')
            return

    print('NO')


for _ in range(t):
    main()
