def main():
    t = int(input())
    for case in range(t):
        n, m = input().split()
        s1 = set(input().split())
        s2 = set(input().split())
        res = s1.intersection(s2)
        if len(res) == 0:
            print("NO")
        else:
            print("YES")
            print(1, res.pop())


if __name__ == "__main__":
    main()
