Problem:

#include<bits/stdc++.h>

using namespace std;

int check(string &a, string &b){

while(a.size()<b.size()) a += ‘0’;

while(a.size()>b.size()) b += ‘0’;

a += ‘0’, b += ‘0’;

int carry = 0, k = 0, ans = 0;

bool flag = false;

for(int i=a.size()-1; i>=0; i–){

if(a[i] == ‘1’ && b[i] == ‘1’){

// Carry genration

if(flag)

k = 0;

flag = true;

}

else if((a[i]== ‘0’ && b[i] == ‘1’) || (a[i] == ‘1’ && b[i] == ‘0’)){

// Carry propogation

if(flag)

k++;

}

else{

flag = false;

k = 0;

}

ans = max(ans, k);

}

return ans + 1;

}

int main(){

int t;

cin >> t;

while(t–){

string a, b;

cin >> a >> b;

if(count(b.begin(), b.end(), ‘0’) == b.length()){

cout << 0 << endl;

continue;

}

reverse(a.begin(), a.end());

reverse(b.begin(), b.end());

cout << check(a, b) << ‘\n’;

}

}