WA on last test case in CRDFLP

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000007
#define MAX 20000000000
#define set_zero(a) memset(a,0,sizeof(a))
#define init_dp(a) memset(a,-1,sizeof(a))
#define trace(x) cerr<<#x<<" "<<x<<" "<<endl;
#define N1 50000
#define pi 3.14
using namespace std;
string decToBinary(ll n){
   if(n == 0) return "0";
   ll binaryNum[65];
   ll i = 0;
   string s;
   while (n > 0) {
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
   }
   for(ll j = 0 ; j < i ; j++){
       if(binaryNum[j] == 1) s.push_back('1');
       else s.push_back('0');
    }
    return s;
}
void solve(ll tc){
   ll n; cin>>n;
   ll a[n], b[n];
   vector<pair<ll,ll>> ans;
   for(ll i = 0;i<n;i++){
      cin>>a[i];
   }
   ll sum = a[0];
   for(ll i = 1;i<n;i++) sum &= a[i];
   ans.push_back({sum,0});
   for(ll i = 0;i<n;i++) cin>>b[i];
   sum = b[0];
   for(ll i = 1;i<n;i++){
      sum &= b[i];
   }
   ans.push_back({sum,n});
   for(ll j = 65;j>=0;j--){
      bool ok = true;
      vector<ll> v; ll cnt = 0;
      for(ll i = 0;i<n;i++){
         string x = decToBinary(a[i]);
         string y = decToBinary(b[i]);
         if(j < x.length() && x[j] == '1') v.push_back(a[i]);
         else if( j < y.length() && y[j] == '1'){
            v.push_back(b[i]); cnt++;
         }
         else{
            ok = false; break;
         }
      }
      if(ok){
         ll sum1 = v[0];
         for(ll i = 1;i<v.size();i++) sum1 &= v[i];
         ans.push_back({sum1,cnt});
      }
   }
   ll ans1 = 0,ans2 = 1e18;
   for(auto p : ans){
      ans1 = max(ans1,p.first);
   }
   for(ll i = 0;i<ans.size();i++){
      if(ans[i].first == ans1) ans2 = min(ans2,ans[i].second);
   }
   if(ans2 == 1e18) ans2 = 0;
   cout << ans1 << " " << ans2 << "\n";
}
int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(NULL); cout.tie(NULL);
   ll t = 1; 
   cin>>t;
   ll tc = 0;
   while(t--){
      tc++; solve(tc);
   }
   return 0;
}