#include using namespace std; namespace JiKai_Thinks_ZiQi_Is_Delicious { int T, n; string s1, s2, t1, t2; void main() { cin >> T; while (T--) { cin >> n >> s1 >> s2 >> t1 >> t2; s1 += '0'; s2 += '1'; t1 += '0'; t2 += '0'; int c1[2] = {0, 0}, c2[2] = {0, 0}, ans = 0; for (int i = 0, j = 0; i <= n && j <= n;) { while (t1[i] != '0') s1[i] == '0' ? c1[0]++ : c1[1]++, i++; while (t2[j] != '0') s2[j] == '0' ? c2[0]++ : c2[1]++, j++; if (i == j) ans += min(c1[0], c2[0]) + min(c1[1], c2[1]) + (s1[i] == s2[j]), c1[0] = c1[1] = c2[0] = c2[1] = 0, i++, j++; else if (i < j) { s1[i] == '0' ? c1[0]++ : c1[1]++; i++; if (c1[0] <= c2[0]) ans += c1[0], c2[0] -= c1[0], c1[0] = 0; else ans += c2[0], c2[1] -= c1[0] - c2[0], c1[0] = c2[0] = 0; if (c1[1] <= c2[1]) ans += c1[1], c2[1] -= c1[1], c1[1] = 0; else ans += c2[1], c2[0] -= c1[1] - c2[1], c1[1] = c2[1] = 0; } else { s2[j] == '0' ? c2[0]++ : c2[1]++; j++; if (c2[0] <= c1[0]) ans += c2[0], c1[0] -= c2[0], c2[0] = 0; else ans += c1[0], c1[1] -= c2[0] - c1[0], c2[0] = c1[0] = 0; if (c2[1] <= c1[1]) ans += c2[1], c1[1] -= c2[1], c2[1] = 0; else ans += c1[1], c1[0] -= c2[1] - c1[1], c2[1] = c1[1] = 0; } } cout << ans << "\n"; } } } int main() { freopen("edit.in", "r", stdin); freopen("edit.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); JiKai_Thinks_ZiQi_Is_Delicious::main(); return 0; }