from collections import defaultdict
from functools import reduce
from bisect import bisect_right
from bisect import bisect_left
import copy
import atexit, io, sys
def main():
    buffer = io.BytesIO() 
    sys.stdout = buffer

    @atexit.register 
    def write(): 
        sys.__stdout__.write(buffer.getvalue())
    for _ in range(input()):
        n,m=map(int,raw_input().split())
        a=map(int,raw_input().split())
        b=map(int,raw_input().split())
        a.sort()
        b.sort()
        k=0
        v=0
        i=0
        j=0
        while i<n and j<m:
                if a[i]==b[j]:
                    k=1
                    v=a[i]
                    break
                elif a[i]<b[j]:
                    i+=1
                else:
                    j+=1
        if k:
            print('YES')
            print 1,v
        else:
            print('NO')
                


if __name__ == '__main__':
    main()