Help me in solving APPENDOR problem

My issue

how is this logic wrong for the 3rd test case…doesnt make sense

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	long int a,b,c=0,test;
	cin>>test; 
	while(test--){
	    cin>>a>>b;
	    long arr[a];
	    bool d=false;
	    for(int i=0;i<a;i++){
	        cin>>arr[i];
	        c=c|arr[i];
	    }
	    for(int j=0;j<=b;j++){
	        if((c|j)==b){
	            cout<<j<<endl;
	            d=true;
	            break;
	        }
	    }
	    if(!d){
	        cout<<"-1"<<endl;
	    }
	}
	return 0;
}

Problem Link: Append for OR Practice Coding Problem - CodeChef

@mayukh_biswas3
plzz refer my c++ solution for better understanding of the logic

using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n>>k;
	    int a[n];
	    int sm=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        sm=sm|a[i];
	    }
	    int ch=sm&k;
	    if(ch==sm)
	    {
	        int ans=sm^k;
	        cout<<ans;
	    }
	    else
	    cout<<-1;
	    cout<<endl;
	}

}