Help me in solving CS2023_PON problem

My issue

My code

def find_subsequence_exists(T, test_cases):
    result = []
    for _ in range(T):
        N, B = test_cases[_][0]
        A = test_cases[_][1]
        subsequence_exists = False
        for bitmask in range(1, 2**N):
            bitwise_and = None
            for i in range(N):
                if bitmask & (1 << i):
                    if bitwise_and is None:
                        bitwise_and = A[i]
                        bitwise_and &= A[i]
            if bitwise_and == B:
                subsequence_exists = True
        result.append("YES" if subsequence_exists else "NO")
    return result

# Read input
T = int(input())
test_cases = []
for _ in range(T):
    N, B = map(int, input().split())
    A = list(map(int, input().split()))
    test_cases.append(((N, B), A))

# Solve the problem
output = find_subsequence_exists(T, test_cases)

# Print output
for result in output:

Problem Link: CS2023_PON Problem - CodeChef

Hi there, welcome to the community.

In this question, you have to take Bit wise and of all the numbers that has all the set bits of number b.

For example, if b = 5, we have to take all the numbers from the array that have 20 bit and 22 bit set, for example, 7, 13, 21, 15 etc.

Now, if their and is equal to 5, then it should print YES, else NO