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

for _ in range(int(input())):
    q = input().split()
    len_a = int(q[0])
    len_b = int(q[1])
    a = input().split()
    b = input().split()
    for i in range(len_a):
        a[i] = int(a[i])
    for i in range(len_b):
        b[i] = int(b[i])
    a.sort()
    b.sort()
    flag = 0
    if len_a == 1:
        if a[0] in b:
            flag = 1
            print('YES')
            print(1, a[0])
    elif len_b== 1:
        if b[0] in a:
            flag = 1
            print('YES')
            print(1, b[0])
    elif len_a <= len_b:
        for i in range(len_a):
            if flag == 1:
                break
            d = 0
            while d < len_b - 1 and b[d] < a[i]: 
                d += 1
            if b[d] == a[i]:
                flag = 1
                print('YES')
                print(1, a[i])
    else:
        for i in range(len_b):
            if flag == 1:
                break
            d = 0
            while b[i] > a[d] and d < len_a - 1:
                d += 1
            if b[i] == a[d]:
                flag = 1
                print('YES')
                print(1, b[i])
    if flag == 0:
        print('NO')