def common(a,b):
    a = set(a)
    b = set(b)
    for i in a:
        if i in b:
            print('YES')
            print('1',i)
            return
    print('NO')
if __name__ == '__main__':
    t = int(input())
    for _ in range(t):
        nm = list(map(int,input().split()))
        a = list(map(int,input().split()))
        b = list(map(int,input().split()))
        common(a,b)