1
2 2
1 1
1 2
 1
1 3
3
1 2 3
 1
1 1
1000
1000
 1
2 2
2 2
2 2
 5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5
 1
4 4
1 1 1 1
1 2 3 4
 1
2 3
1 1
1 2 3

YES
1 1
 YES
1 3
 YES
1 1000
 YES
1 2
 YES
1 4
YES
1 3
NO
YES
1 3
YES
1 1
 YES
1 1
 YES
1 1

#!/usr/bin/env python3

def solve(a, b):
    ans = []
    # Set everything in a equal to last element
    # Up to n - 1
    for i in range(len(a) - 1):
        if a[i] != a[i + 1]:
            ans.append(i + 1)

    curr = a[-1]
    for i in range(len(a) - 1, -1, -1):
        if curr != b[i]:
            ans.append(i + 1)
            curr = not curr

    print(len(ans), " ".join(map(str, ans)))

def main():
    t = int(input())
    for _ in range(t):
        n, m = list(map(int, input().split()))
        a = list(map(int, input().split()))
        b = list(map(int, input().split()))
        x = sorted(set(a).intersection(set(b)))
        if x == []:
            print("NO")
        else:
            print("YES")
            print(1, x[0])


if __name__ == "__main__":
    main()
