function solve(n, gregor, me) {
  var taken = new Array(n).fill(0);
  var score = 0;

  for (var i = 0; i < n; i++) {
    if (gregor[i] === "1") taken[i] = 1;
  }

  for (var _i = 0; _i < n; _i++) {
    if (me[_i] !== "1") continue;

    if (_i - 1 >= 0 && taken[_i - 1] === 1) {
      score++;
      taken[_i - 1] = 2;
    } else if (taken[_i] === 0) {
      taken[_i] = 2;
      score++;
    } else if (_i + 1 < n && taken[_i + 1] === 1) {
      score++;
      taken[_i + 1] = 2;
    }
  }

  return score;
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
  n = parseInt(readline());
  var gregor = readline();
  var me = readline();
  print(solve(n, gregor, me));
}

var t = readline()

while (t--) {
    solve();
}

function solve() {
    var n = readline();
    var s = readline();
    var st2 = readline();
    var st = s.split('');
    var cont = 0;

    for (var i = 0; i < n; i++){
        if (st2[i] === '1') {
            if (st[i] === '0') {
                cont++;
                st[i] = '3';
                continue;
            }
            if (i > 0 && st[i - 1] === '1') {
                st[i - 1] = '3';
                cont++;
                continue;
            }
            if (i < n - 1 && st[i + 1] === '1') {
                st[i + 1] = '3';
                cont++;
            }
        }
    }
    write(cont + '\n');
}

const main = () => {

	var t = readInt();
	var allans = [];
	while (t-- > 0) {
		var n = readInt();
		var enemy = readline().split("").map(zzzz => parseInt(zzzz));
		var gregor = readline().split("").map(zzzz => parseInt(zzzz));
		var cnt = 0;
		for (var i = 0; i < n; i++) {
			if (gregor[i] === 0)
				continue;
			if (i - 1 >= 0 && enemy[i - 1] === 1) { // take pawn on left
				cnt++;
				continue;
			}
			if (enemy[i] === 0) { //go straight
				cnt++;
				continue;
			}
			if (i + 1 < n && enemy[i + 1] === 1) { //take pawn on right
				cnt++
				enemy[i + 1] = -1; // can't use this grid anymore
				continue;
			}
		}
		allans.push(cnt);
	}
	multiLineArrayPrint(allans);

	return;
}

const readInt = () => parseInt(readline());
const readString = () => readline();
const readIntArr = () => readline().split(" ").map(zzzz => parseInt(zzzz));
const parseLong = (string) => { // javascript's largest long is < (1<<62)
	var n = string.length;
	var res = 0;
	for (var i = 0; i < n; i++) {
		res *= 10;
		res += parseInt(string[i]);
	}
	return res;
}
const readLong = () => parseLong(readLong());
const readLongArr = () => readline().split(" ").map(zzzz => parseLong(zzzz));
const oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));
const multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\n'));
const multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\n'));
const makeArr = (defaultVal, dimensionsArr) => {
	var n = dimensionsArr.length;
	if (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);
	else {
		var temp = [];
		for (var i = 0; i < dimensionsArr[0]; i++)
			temp.push(makeArr(defaultVal, dimensionsArr.slice(1)));
		return temp;
	}
}

for (_ = 0; _ < 1; _++) {
	main();
}

// newline for testing
 //newline for testing
// codeforces js cannot use "let" keyword. use "var" instead
// codeforces js cannot destructure arrays

'use strict';

function solve(n, a) {
  const c = a.map(s => s.split('').map(Number));
  const dp = new Array(n).fill(0);
  for (let i = 0; i < n; i++) {
    var _dp;
    if (c[1][i] === 0) dp[i] = (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0;else {
      var _dp2, _dp4;
      if (c[0][i] === 0 || c[0][i - 1] === 1) dp[i] = ((_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0) + 1;else if (c[0][i + 1] === 1) {
        var _dp3;
        dp[i] = ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1;
        c[0][i + 1] = 2;
      } else dp[i] = (_dp4 = dp[i - 1]) !== null && _dp4 !== void 0 ? _dp4 : 0;
    }
  }
  return dp[n - 1];
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = [];
      let tmp = 2;
      while (tmp--) {
        a.push(await read());
      }
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var s = nextCharArray();
		var v = nextCharArray();
		var output = 0;
		for(var i = 0; i < N; i++){
			if(v[i] == "1"){
				if(s[i] == "0"){
					output++;
					continue;
				}
				if(i > 0){
					if(s[i - 1] == "1"){
						s[i - 1] = "0";
						output++;
						continue;
					}
				}
				if(i < N - 1){
					if(s[i + 1] == "1"){
						s[i + 1] = "0";
						output++;
						continue;
					}
				}

			}
		}
		myout(output);
	}
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function printline(s, end = '\n') {
  process.stdout.write(s + end);
}

function main() {
  let t = parseInt(readline(), 10);
  while(t--) {
    const n = parseInt(readline(), 10);
    let enemy = readline().split('');
    const paws = readline();

    let ans = 0;

    for (let i = 0; i < n; ++i) {
      if (paws[i] === '1') {
        if (enemy[i] === '0') {
          ans++;
          enemy[i] = '2';
        } else {
          if (i > 0 && enemy[i-1] === '1') {
            ans++;
            enemy[i-1] = '2';
          } else if (i < n && enemy[i+1] === '1') {
            ans++;
            enemy[i+1] = '2';
          }
        }
      }
    }

    printline(ans);
  }
}

// run: cat input.txt | node B.js

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

var maxN = 2 * 1e5 + 10
var mod = 1e9 + 7

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    var a = readline().split('').map((x, iii) => {
      return parseInt(x)
    })
    var b = readline().split('').map((x, iii) => {
      return parseInt(x)
    })
    var res = 0
    for (let j = 0; j < n; j++) {
      if (b[j] === 1 && a[j] === 0 ) {
        res++
        continue
      }

      if (b[j] === 1 && a[j - 1] === 1 && j - 1 >= 0) {
        res++
        a[j - 1] = 0
        continue
      }
      if (b[j] === 1 && a[j + 1] === 1 && j + 1 < n) {
        res++
        a[j + 1] = 0
        continue
      }
    }

    console.log(res)
  })
  // var res = new Array(n)
}

function plus(a, b, res) {
// console.log(a, b, res)
  if (a === 0) return res

  return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)
}

var fs = require("fs");
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const lines = stdinBuffer.toString().match(/[^\r\n]+/g).slice(1);

const examples = [];

for(let i = 0; i < lines.length; i+= 3) {
    examples.push([
        lines[i+1].split('').map(letter => letter === '1'),
        lines[i+2].split('').map(letter => letter === '1'),
    ]);
}

const solver = (arr) => {
    let currentResult = 0;
    arr[0].forEach((top, index) => {
        // console.log(currentResult, index)
        const bottom = Boolean(arr[1][index]);
        const bottomRight = Boolean(arr[1][index + 1]);

        if ((top && arr[1][index - 1])) {
            currentResult++;
            arr[1][index - 1] = false;
            return;
        }
        if ((top === false && bottom)) {
            currentResult++;
            arr[1][index] = false;
            return;
        }
        if ((top && bottomRight)) {
            currentResult++;
            arr[1][index + 1] = false;
        }
    })
    return currentResult
};

// console.log(examples)

for(let example of examples) {
    console.log(solver(example))
}

var testCasesCount = readline();

for(var i=0; i<testCasesCount; i++){

    var noOfPawnsCanReachEndline = 0;

    var chesssize = readline();

    var enemyArray = readline().split("");
    var playerArray = readline().split("");

    for(var playerPawn =0; playerPawn<playerArray.length; playerPawn++){
        if(playerArray[playerPawn] === '1'){ // if player pawn exists
            if(enemyArray[playerPawn] === '0'){ // if enemy player doest not exist
                noOfPawnsCanReachEndline ++;
            }else if(enemyArray[playerPawn-1] === '1'){ // if enemy player exist diagonally
                noOfPawnsCanReachEndline ++;
                enemyArray[playerPawn-1] = 0;
            }else if(enemyArray[playerPawn+1] === '1'){ // if enemy player exist diagonally
                noOfPawnsCanReachEndline ++;
                enemyArray[playerPawn+1] = 0;
            }
        }
    }

    print(noOfPawnsCanReachEndline);

}

'use strict';

function solve(n, a) {
  const c = a.map(s => s.split('').map(Number));
  const dp = new Array(n).fill(0);
  for (let i = 0; i < n; i++) {
    var _dp;
    if (c[1][i] === 0) dp[i] = (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0;else {
      var _dp2;
      if (c[0][i] === 0 || c[0][i - 1] === 1) dp[i] = ((_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0) + 1;else if (c[0][i + 1] === 1) {
        var _dp3;
        dp[i] = ((_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0) + 1;
        c[0][i + 1] = 2;
      }
    }
  }
  return dp[n - 1];
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = [];
      let tmp = 2;
      while (tmp--) {
        a.push(await read());
      }
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var s = nextCharArray();
		var v = nextCharArray();
		var output = 0;
		for(var i = 0; i < N; i++){
			if(v[i] == "1"){
				if(s[i] == "0"){
					output++;
					continue;
				}
				if(i < N - 1){
					if(s[i + 1] == "1"){
						s[i + 1] = "0";
						output++;
						continue;
					}
				}
				if(i > 0){
					if(s[i - 1] == "1"){
						s[i - 1] = "0";
						output++;
						continue;
					}
				}
			}
		}
		myout(output);
	}
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

var maxN = 2 * 1e5 + 10
var mod = 1e9 + 7

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    var a = readline().split('').map((x, iii) => {
      return parseInt(x)
    })
    var b = readline().split('').map((x, iii) => {
      return parseInt(x)
    })
    var res = 0
    for (let j = 0; j < n; j++) {
      if (b[j] === 1 && a[j] === 0 ) {
        res++
        continue
      }

      if (b[j] === 1 && a[j + 1] === 1 && j + 1 < n) {
        res++
        a[j + 1] = 0
        continue
      }
      if (b[j] === 1 && a[j - 1] === 1 && j - 1 >= 0) {
        res++
        a[j - 1] = 0
        continue
      }
    }

    console.log(res)
  })
  // var res = new Array(n)
}

function plus(a, b, res) {
// console.log(a, b, res)
  if (a === 0) return res

  return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)
}

var testCasesCount = readline();

for(var i=0; i<testCasesCount; i++){

    var noOfPawnsCanReachEndline = 0;

    var chesssize = readline();

    var enemyArray = readline().split("");
    var playerArray = readline().split("");

    for(var playerPawn =0; playerPawn<playerArray.length; playerPawn++){
        if(playerArray[playerPawn] === '1'){ // if player pawn exists
            if(enemyArray[playerPawn] === '0'){ // if enemy player doest not exist
                noOfPawnsCanReachEndline ++;
            }else if(enemyArray[playerPawn+1] === '1'){ // if enemy player exist diagonally
                noOfPawnsCanReachEndline ++;
                enemyArray[playerPawn+1] = 0;
            }else if(enemyArray[playerPawn-1] === '1'){ // if enemy player exist diagonally
                noOfPawnsCanReachEndline ++;
                enemyArray[playerPawn-1] = 0;
            }
        }
    }

    print(noOfPawnsCanReachEndline);

}

var testCasesCount = readline();

var noOfPawnsCanReachEndline = 0;

for(var i=0; i<testCasesCount; i++){

    var chesssize = readline();

    var enemyArray = readline().split("");
    var playerArray = readline().split("");

    for(var playerPawn =0; playerPawn<playerArray.length; playerPawn++){
        if(playerArray[playerPawn] === '1'){ // if player pawn exists
            if(enemyArray[playerPawn] === '0'){ // if enemy player doest not exist
                noOfPawnsCanReachEndline ++;
            }else if(enemyArray[playerPawn+1] === '1'){ // if enemy player exist diagonally
                noOfPawnsCanReachEndline ++;
                enemyArray[playerPawn+1] = 0;
            }
        }
    }

    print(noOfPawnsCanReachEndline);

}

var testCasesCount = readline();

var noOfPawnsCanReachEndline = 0;

for(var i=0; i<testCasesCount; i++){

    var chesssize = readline();

    var enemyArray = readline().split("");
    var playerArray = readline().split("");

    for(var playerPawn =0; playerPawn<playerArray.length; playerPawn++){
        if(playerArray[playerPawn] === '1'){ // if player pawn exists
            if(enemyArray[playerPawn] === '0'){ // if enemy player doest not exist
                noOfPawnsCanReachEndline ++;
            }else if(enemyArray[playerPawn+1] === '1'){ // if enemy player exist diagonally
                noOfPawnsCanReachEndline ++;
                enemyArray[playerPawn+1] = 0;
            }
        }
    }

}

var testCasesCount = readline();

var noOfPawnsCanReachEndline = 0;

for(var i=0; i<testCasesCount; i++){

    var chesssize = readline();

    var enemyArray = readline().split("");
    var playerArray = readline().split("");

    for(var playerPawn =0; playerPawn<playerArray.length; playerPawn++){
        if(playerArray[playerPawn] === 1){ // if player pawn exists
            if(enemyArray[playerPawn] === 0){ // if enemy player doest not exist
                noOfPawnsCanReachEndline ++;
            }else if(enemyArray[playerPawn+1] === 1){ // if enemy player exist diagonally
                noOfPawnsCanReachEndline ++;
                enemyArray[playerPawn+1] = 0;
            }
        }
    }

    print(noOfPawnsCanReachEndline);

}

var testCasesCount = readline();

var noOfPawnsCanReachEndline = 0;

for(var i=0; i<testCasesCount; i++){

    var chesssize = readline();

    var enemyArray = readline().split("");
    var playerArray = readline().split("");

    for(var playerPawn =0; playerPawn<playerArray.length; playerPawn++){
        if(playerArray[playerPawn] === 1){ // if player pawn exists
            if(enemyArray[playerPawn] === 0){ // if enemy player doest not exist
                noOfPawnsCanReachEndline ++;
            }else if(enemyArray[playerPawn+1] === 1){ // if enemy player exist diagonally
                noOfPawnsCanReachEndline ++;
                enemyArray[playerPawn+1] = 0;
            }
        }
    }

}

function solve(n, gregor, me) {
  var taken = new Array(n).fill(false);
  var score = 0;

  for (var i = 0; i < n; i++) {
    if (gregor[i] === "1") taken[i] = true;
  }

  for (var _i = 0; _i < n; _i++) {
    if (me[_i] !== "1") continue;

    if (_i - 1 >= 0 && taken[_i - 1]) {
      score++;
      taken[_i - 1] = true;
    } else if (!taken[_i]) {
      taken[_i] = true;
      score++;
    } else if (_i + 1 < n && taken[_i + 1]) {
      score++;
      taken[_i + 1] = true;
    }
  }

  return score;
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
  n = parseInt(readline());
  var gregor = readline();
  var me = readline();
  print(solve(n, gregor, me));
}

function solve(n, gregor, me) {
  var taken = new Array(n).fill(false);
  var score = 0;

  for (var i = 0; i < n; i++) {
    if (gregor[i] === "1") taken[i] = true;
  }

  for (var _i = 0; _i < n; _i++) {
    if (me[_i] !== "1") continue;

    if (_i - 1 >= 0 && taken[_i - 1]) {
      score++;
      taken[_i - 1] = true;
    } else if (!taken[_i]) {
      taken[_i] = true;
      score++;
    } else if (_i + 1 < n && taken[_i + 1]) {
      score++;
      taken[_i + 1] = true;
    }
  }

  return score;
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
  n = parseInt(readline());
  gregor = readline();
  me = readline();
  print(solve(n, gregor, me));
}

var t = readline()

while (t--) {
    solve();
}

function solve() {
    var n = readline();
    var st = readline();
    var st2 = readline();

    var cont = 0;

    for (var i = 0; i < n; i++){
        if (st2[i] === '1') {
            if (st[i] === '0') {
                cont++;
                st[i] = '3';
                continue;
            }
            if (i > 0 && st[i - 1] === '1') {
                st[i - 1] = '3';
                cont++;
                continue;
            }
            if (i < n - 1 && st[i + 1] === '1') {
                st[i + 1] = 3;
                cont++;
            }
        }
    }

    write(cont + '\n');
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5

**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function lcm(a, b) {
    return (a / gcd(a, b) * b);
}

function main() {
    let n = Number(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let [n, t] = readline().split(" ").map(Number);
    let data = readline().split(" ").map(Number);

    //let output = [];
    let total = 0;

    for(let i=0;i<data.length;i++) {
        total = total + data[i];
        if(total === t && i+1 !== data.length) {
            [data[i], data[i+1]] = [data[i+1], data[i]];
        }
    }

    if(total === t) {
        console.log('No');
    } else {
        console.log('Yes');
        console.log(data.join(" "));
    }

}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var X = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var sum = 0;
		for(var j = 0; j < N; j++){
			sum += list[j];
		}
		if(sum == X){
			myout("NO");
		}else{
			myout("YES");
			while(true){
				var sum = 0;
				var isOK = true;
				for(var j = 0; j < N; j++){
					sum += list[j];
					if(sum == X){
						isOK = false;
						break;
					}
				}
				if(isOK){
					break;
				}else{
					list.push(list.shift());
				}
			}
			myout(myconv(list, 8));
		}
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var X = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var sum = 0;
		for(var j = 0; j < N; j++){
			sum += list[j];
		}
		if(sum == X){
			myout("NO");
		}else{
			myout("YES");
			if(list[0] == X){
				list.push(list.shift());
			}
			myout(myconv(list, 8));
		}
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var X = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var sum = 0;
		for(var j = 0; j < N; j++){
			sum += list[j];
		}
		if(sum == X){
			myout("NO");
		}else{
			myout("YES");
			myout(myconv(list, 8));
		}
	}
}


const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, k, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, arr) {
    let ans = 0
    for (let i = 0; i <= 30; i++) {
        let now = 0
        arr.forEach(x => {
            if (x & (1 << i)) now++
        })
        if (now >= n / 2) {
            ans |= 1 << i
        }
    }
    return ans
}

let dataitr;
let stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", (input) => {
  stdin_input += input;
});
process.stdin.on("end", () => {
  dataitr = stdin_input.split("\n").values();
  main();
});

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(" ");
const rna = () => ra().map((x) => Number(x));
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const t = rn();

  for (let ti = 0; ti < t; ti++) {
    const [n, l] = rna();
    const x = rna();

    const hash = Array.from({ length: l }, () => 0);

    for (const xi of x) {
      const s = xi.toString(2).padStart(l, "0");
      for (let i = 0; i < s.length; i++) {
        if (s[i] === "1") {
          hash[i]++;
        } else {
          hash[i]--;
        }
      }
    }

    let local = "";
    for (let i = 0; i < hash.length; i++) {
      if (hash[i] > 0) {
        local += "1";
      } else {
        local += "0";
      }
    }

    console.log(parseInt(local, 2));
  }
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;

	let t = inputReader.readNumber();

	function solve() {
	  let [n,l] = inputReader.readNumberArray();
	  let v = inputReader.readNumberArray();
	  let bits = new Array(l).fill(0);
	  v.forEach(x => {
	    for(let k = 0; k < l; k++){
	      bits[k]+= x & (1 << k) ? 1 : 0;
	    }
	  });
	  let ans = 0;
	  for(let k = 0; k < l; k++){
	    if(bits[k] > (n - bits[k])) ans += (1 << k);
	  }
	  console.log(ans);
	}

	while (t--) {
	  solve();
	}
}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const [n, l] = rna();
		const x = rna();

		let ans = 0;
		for (let i = 0; i < l; i++) {
			let cnt = 0;
			for (let j = 0; j < n; j++) {
				cnt += (x[j] >> i) & 1;
			}
			if (cnt >= n - cnt)
				ans += 1 << i;
		}

		console.log(ans);
	}
}