def main():
    t = int(input())
    for i in range(t):
        [m , n] = list(map(int, input().split()))
        x = set(map(int, input().split()))
        y = list(map(int, input().split()))
        r = -1
        for i in y:
            if i in x:
                r = i
        if r != -1:
            print('YES')
            print(1, r)
        else:
            print('NO')
            
if __name__ == "__main__":
    main()
