// SPDX-License-Identifier: Unlicense
// Author: Bingwu Zhang <xtex@xtexx.eu.org>
#include <bits/stdc++.h>

#define uint unsigned int
#define expT(x) __builtin_expect(x, 1)
#define expF(x) __builtin_expect(x, 0)

namespace xtex
{

    uint rdu()
    {
        uint v = 0;
        char ch = getchar();
        while (!(ch >= '0' && ch <= '9'))
            ch = getchar();
        while (ch >= '0' && ch <= '9')
        {
            v = (v << 3) + (v << 1) + (ch ^ '0');
            ch = getchar();
        }
        return v;
    }

#define MAXN 100005
#define BS std::bitset<MAXN>
    uint n;
    BS s1, s2, t1, t2, lk;

    void rdbitset(BS &bs)
    {
        char ch = getchar();
        while (!(ch >= '0' && ch <= '9'))
            ch = getchar();
        for (uint i = 1; i <= n; ++i)
        {
            bs[i] = (ch & 1);
            ch = getchar();
        }
    }

    inline uint findFlip(BS &s, BS &t, uint pos)
    {
        bool goal = !s[pos];
        for (uint i = pos - 1; i > 0; --i)
        {
            if (expF(!t[i]))
                break;
            if (expF(!lk[i] && s[i] == goal))
            {
                s[i].flip(), s[pos].flip();
                return i;
            }
        }
        for (uint i = pos + 1; i <= n; ++i)
        {
            if (expF(!t[i]))
                break;
            if (expF(!lk[i] && s[i] == goal))
            {
                s[i].flip(), s[pos].flip();
                return i;
            }
        }
        // uint l = pos - 1, r = pos + 1;
        // while ((l > 0) && (r <= n))
        // {
        //     if (expF(!t[l]))
        //     {
        //         l = 0;
        //         break;
        //     }
        //     if (expF(!t[r]))
        //     {
        //         r = 0xfffff;
        //         break;
        //     }
        //     if (expF(!lk[i] && s[i] == goal))
        //     {
        //         s[i].flip(), s[pos].flip();
        //         return i;
        //     }
        // }
        // for (uint i = pos - 1; i > 0; --i)
        // {
        //     if (expF(!t[i]))
        //         break;
        //     if (expF(!lk[i] && s[i] == goal))
        //     {
        //         s[i].flip(), s[pos].flip();
        //         return i;
        //     }
        // }
        return 0;
    }

    uint sol()
    {
        for (uint i = 1; i <= n; ++i)
            lk[i] = false;
        // s1.reset(), s2.reset(), t1.reset(), t2.reset(), lk.reset();
        n = rdu();
        rdbitset(s1);
        rdbitset(s2);
        rdbitset(t1);
        rdbitset(t2);
        uint ans = 0;

        // 性质A
        {
            bool propA = true;
            bool vs1 = s1[1];
            for (uint i = 2; i <= n; ++i)
                if (t1[i] != vs1)
                {
                    propA = false;
                    break;
                }
            if (propA)
            {
                for (uint i = 1; i <= n; ++i)
                    if (s2[i] == vs1)
                        ++ans;
                return ans;
            }
        }

        for (uint i = 1; i <= n; ++i)
            // 1中被锁，在2找相同位
            if (expF(!t1[i] && t2[i]))
            {
                if (s1[i] != s2[i])
                {
                    uint ret = findFlip(s2, t2, i);
                    if (ret != 0)
                        ++ans, lk[i] = true;
                }
                else
                    ++ans, lk[i] = true;
            }
            // 2中被锁，在1找相同位
            else if (expF(!t2[i] && t1[i]))
            {
                if (s1[i] != s2[i])
                {
                    uint ret = findFlip(s1, t1, i);
                    if (ret != 0)
                        ++ans, lk[i] = true;
                }
                else
                    ++ans, lk[i] = true;
            }
        for (uint i = 1; i <= n; ++i)
        {
            if (expT(lk[i]))
                continue;
            if (expT(t1[i] && t2[i]))
            {
                // 1,2均未被锁定
                if (s1[i] == s2[i])
                    ++ans, lk[i] = true;
                else
                {
                    uint ret = findFlip(s2, t2, i);
                    if (ret != 0)
                        ++ans, lk[i] = true;
                    else
                    {
                        ret = findFlip(s1, t1, i);
                        if (ret != 0)
                            ++ans, lk[i] = true;
                    }
                }
            }
            else if (s1[i] == s2[i])
                ++ans;
        }
        // std::cout << "s1: " << s1 << '\n';
        // std::cout << "s2: " << s2 << '\n';
        // std::cout << "lk: " << lk << '\n';
        return ans;
    }

}

int main()
{
    using namespace xtex;
    freopen("edit.in", "r", stdin);
    freopen("edit.out", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    uint T = rdu();
    while (T--)
    {
        uint ans = sol();
        printf("%u\n", ans);
    }
    return 0;
}

/**
 * 9:49了
 * 高二老登AFO前的最后一次参赛
 * T1不会做，哎，TLE
 * https://xtexx.eu.org
 * The Last Dance
 * 12:51了
 * Goodbye, AFOed
 * 感谢两年来支持我的各位老师和同学
 * Sat, 30 Nov 2024 12:53:52 +0800 @ 中山纪中
 */
