//#pragma warning(disable:4786)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<map>
#include<ctime>
#include<string.h>
using namespace std;

#define pi acos(-1.0)
#define LL __int64
//typedef long long LL;
#define INF 0x7fffffffffffffff
#define bug puts("hear!")
#define inf 500000001
#define eps 1e-8
#define FRE freopen("in.txt","r",stdin)
#define E exp(1.0)

#define N 101

int a[50005];
int dp[10001][3];

int main()
{
  //  FRE;
    int t;
    scanf("%d", &t);
    char ch;
    int n;
    while(t--)
    {
        scanf("%d", &n);
        getchar();
        for(int i = 1; i <= 4 * n; i++)
        {
            scanf("%c", &ch);
            a[i] = ch == 'N' ? 0 : 1;
        }
        if(a[1] && a[1 + 2 * n])
        {
            dp[0][0] = 3;
            dp[0][1] = 2;
            dp[0][2] = 2;
        }
        else if(a[1])
        {
            dp[0][0] = 1;
            dp[0][1] = 1;
            dp[0][2] = 2;
        }
        else if(a[1 + 2 * n])
        {
            dp[0][0] = 3;
            dp[0][1] = 2;
            dp[0][2] = 2;
        }
        else
        {
            dp[0][0] = 0;
            dp[0][1] = 1;
            dp[0][2] = 2;
        }
   //     cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl;
        int flag1, flag2;
        for(int i = 2; i <= 2 * n; i += 2)
        {
            flag1 = flag2 = 0;
            if(i == 2 * n)
            {
                if(a[i]) flag1 = 1;
                if(a[i * 2]) flag2 = 1;
            }
            else
            {
                if(a[i] || a[i + 1]) flag1 = 1;
                if(a[i + 2 * n] || a[i + 2 * n + 1]) flag2 = 1;
            }
            i = i / 2;
        //    cout<<flag1<<" "<<flag2<<endl;
            if(flag1 && flag2)
            {
                dp[i][0] = min(dp[i - 1][0] + 4, min(dp[i - 1][1] + 3, dp[i - 1][2] + 3));
                dp[i][1] = min(dp[i - 1][0] + 3, min(dp[i - 1][1] + 3, dp[i - 1][2] + 3));
                dp[i][2] = min(dp[i - 1][0] + 3, min(dp[i - 1][1] + 3, dp[i - 1][2] + 4));
            }
            else if(flag1)
            {
                dp[i][0] = min(dp[i - 1][0] + 2, min(dp[i - 1][1] + 2, dp[i - 1][2] + 3));
                dp[i][1] = min(dp[i - 1][0] + 2, min(dp[i - 1][1] + 2, dp[i - 1][2] + 3));
                dp[i][2] = min(dp[i - 1][0] + 3, min(dp[i - 1][1] + 3, dp[i - 1][2] + 4));
            }
            else if(flag2)
            {
                dp[i][0] = min(dp[i - 1][0] + 4, min(dp[i - 1][1] + 3, dp[i - 1][2] + 3));
                dp[i][1] = min(dp[i - 1][0] + 3, min(dp[i - 1][1] + 2, dp[i - 1][2] + 2));
                dp[i][2] = min(dp[i - 1][0] + 3, min(dp[i - 1][1] + 2, dp[i - 1][2] + 2));
            }
            else
            {
       //         cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl;
      //          cout<<i<<endl;
                dp[i][0] = min(dp[i - 1][0] + 1, min(dp[i - 1][1] + 2, dp[i - 1][2] + 3));
                dp[i][1] = min(dp[i - 1][0] + 2, min(dp[i - 1][1] + 1, dp[i - 1][2] + 2));
                dp[i][2] = min(dp[i - 1][0] + 3, min(dp[i - 1][1] + 2, dp[i - 1][2] + 1));
            }
            i *= 2;
        }
    //    cout<<dp[1][0]<<endl;
        printf("%d\n", dp[n][0]);
    }
    return 0;
}

Measured memory_bytes: 0