if __name__ == '__main__':
    results = []
    tests = int(input())
    for _x in range(tests):
        n = list(int(item) for item in input().split())
        a = list(int(item) for item in input().split())[:n[0]]
        b = list(int(item) for item in input().split())[:n[1]]
        c = list(set(a) & set(b))
        if len(c) == 0:
            results.append('NO')
        else:
            results.append(f'YES\n1 {c[0]}')
    print(*results, sep='\n')
