def main():
    def find():
        n, m = map(int, input().split())
        a = list(map(int, input().split()))
        b = list(map(int, input().split()))
        for i in a:
            for j in b:
                if i == j:
                    print('YES')
                    print(1, i)
                    return
        print('NO')
    
    t = int(input())
    for _ in range(t):
        find()
                    
            


if __name__ == '__main__':
    main()
