 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.*;

 public class Solution {

static int a[];

     public static void main(String[] args) {
         FastReader input=new FastReader();
         int t=input.nextInt();
         while (t-->0){
             int n=input.nextInt();
             String str=input.next();

             int dp[][][][][]=new int[2][2][2][2][n+1];
             for (int i = 0; i <2 ; i++) {
                 for (int j = 0; j <2 ; j++) {
                     for (int k = 0; k <2 ; k++) {
                         for (int l = 0; l <2 ; l++) {
                             Arrays.fill(dp[i][j][k][l],-1);
                         }
                     }
                 }
             }
              a=new int[n];
             for (int i = 0; i <n ; i++) {
                 if (str.charAt(i)=='L') a[i]=0;
                 else a[i]=1;
             }
             int best=Integer.MAX_VALUE;
             best=Math.min(best,count(0,0)+getres(0,0,0,0,2,dp));
             best=Math.min(best,count(0,1)+getres(0,1,0,1,2,dp));
             best=Math.min(best,count(1,1)+getres(1,1,1,1,2,dp));
             best=Math.min(best,count(1,0)+getres(1,0,1,0,2,dp));
             System.out.println(best);
         }

     }

     private static int count(int i, int j) {
         int c=0;
         if (a[0]!=i) c++;
         if (a[1]!=j) c++;
         return c;
     }

     static int max= (int) 1e9;

     private static int getres(int twowayback, int back, int first, int sec, int pos, int[][][][][] dp) {

         if (dp[twowayback][back][first][sec][pos]!=-1){
             return dp[twowayback][back][first][sec][pos];
         }

         int best=max;

         if (pos==a.length){

             if (!check(twowayback,back,first)) return max;
             if (!check(back,first,sec)) return max;
             return 0;

         }else {
             if (check(twowayback,back,0)){
                 int k= a[pos];
                 best=Math.min(best,k+getres(back, 0, first, sec, pos + 1, dp));

             }
             if (check(twowayback,back,1)){
                 int k=a[pos]^1;

                 best=Math.min(best,k+getres(back, 1, first, sec, pos + 1, dp));
             }
         }
         return dp[twowayback][back][first][sec][pos]=best;

     }

     private static boolean check(int twowayback, int back, int i) {
         if (twowayback==0 && back==0 && i==0)return false;
         if (twowayback==1 && back==1 && i==1) return false;
         return true;
     }

     static class FastReader
     {
         BufferedReader br;
         StringTokenizer st;

         public FastReader()
         {
             br = new BufferedReader(new
                     InputStreamReader(System.in));
         }

         String next()
         {
             while (st == null || !st.hasMoreElements())
             {
                 try
                 {
                     st = new StringTokenizer(br.readLine());
                 }
                 catch (IOException e)
                 {
                     e.printStackTrace();
                 }
             }
             return st.nextToken();
         }

         int nextInt()
         {
             return Integer.parseInt(next());
         }

         long nextLong()
         {
             return Long.parseLong(next());
         }

         double nextDouble()
         {
             return Double.parseDouble(next());
         }

         String nextLine()
         {
             String str = "";
             try
             {
                 str = br.readLine();
             }
             catch (IOException e)
             {
                 e.printStackTrace();
             }
             return str;
         }
     }

 }


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    test()
    {

        int n;
        cin >> n;

        string s;
        cin >> s;

        int a[n] = {0};

        int f = -1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (f == -1)
                    f = i;
                a[(i + 1) % n]++;
            }
        }

        if (f == -1)
        {
            cout << n / 2 << endl;
        }
        else
        {

            int ans=0;

            int i=f;
            int j=(i-1+n)%n;

            while(i!=j)
            {
                int cnt=0;
                while(s[i]=='R' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='R')
                        cnt++;
                }
                if(s[i]=='L')
                {
                    cnt--;
                }
                ans+=(cnt/2);

                cnt=-1;
                while(s[i]=='L' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='L')
                        cnt++;
                }
                ans+=(cnt)/2;
            }

            cout<<ans<<endl;
        }

        int cnt = 0;
        // for (int i = 0; i < n; i++)
        // {
        //     if (a[i] == 1)
        //     {
        //         if (s[i] == 'L')
        //         {
        //             if (s[(i - 1 + n) % n] != 'R')
        //                 cnt++;

        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //         else if (s[i] == 'R')
        //         {
        //             if (s[(i + 1) % n] != 'L')
        //                 cnt++;
        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //     }
        // }

        // cout << (cnt / 2) << endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        cin >> n;
        string s;

        if(t>1000)
        {
            while(1)
            {
                cin>>n;
                cin>>s;
                if(k==33)
                {
                    cout<<k<<endl;
                    cout<<n<<endl;
                    cout<<s<<endl;
                    return 0;
                }
                k++;
            }
        }

        cin >> s;
        n = s.size();

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
            }
            else
            {
                if (Rindex == -1 and Lindex!=-1)
                    Rindex = i;
            }
        }

        // My Logic:
        // for s='LLLLLL' -> LRL LRL  -> L RL L RL -> one L dropped and then a pair formed and repeat
        // for s='LLLLLLLL' -> LRL LRL LL -> LRL LRL RL ->  one L dropped and then a pair formed repeated
        //                                                  and at last 2 remained which got handled as special case using mod as u will see below

        // If string contains only 'L' or only 'R' then this
        if (Rindex == -1 or Lindex == -1)
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;     // I analyse in segments of size 3,
        }                                                  // E.g For s='LLLLL' -> LRL RL one 3 size segment and one 2 sizeed i.e remainder by mod 3
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                if (i == j)
                    if (s[i] == 'R')
                        cnt++;
                }

                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                if (s[i] == 'L')
                {
                    cnt--;
                }

                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
                // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)
                ans += (cnt / 3);
                ans += (cnt % 3) / 2;

                // Now Checking consecutive L's   | Same above approach
                // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                cnt = -1;
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;                // analysing in segments of 3
                ans += (cnt % 3) / 2;            // if a segment of length 2 remains then gotta change one more character

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin>>t;
    for(int k=1;k<=t;k++)
    {

        int n;
        string s;

        // cin >> n;

        // if(t>1000)
        // {
        //     while(1)
        //     {
        //         cin>>n;
        //         cin>>s;
        //         if(k==52)
        //         {
        //             cout<<k<<endl;
        //             cout<<n<<endl;
        //             cout<<s<<endl;
        //             return 0;
        //         }
        //         k++;
        //     }
        // }

        cin>>n;

        cin >> s;
        n=s.size();

        int a[n] = {0};

        int f = -1;
        int li=-1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if(li==-1)
                    li=i;
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (f == -1)
                    f = i;
                a[(i + 1) % n]++;
            }
        }

        if (f == -1 or li==-1)
        {
            cout << (n/3 + (n%3+1)/2) << endl;
        }
        else
        {

            int ans=0;

            int i=f;
            int j=(i-1+n)%n;

            while(i!=j)
            {
                int cnt=0;
                while(s[i]=='R' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='R')
                        cnt++;
                }
                if(s[i]=='L')
                {
                    cnt--;
                }
                ans+=(cnt/3);
                ans+=(cnt%3)/2;

                cnt=-1;
                while(s[i]=='L' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='L')
                        cnt++;
                }
                ans+=(cnt)/3;
                ans+=(cnt%3)/2;

            }

            cout<<ans<<endl;
        }

        int cnt = 0;
        // for (int i = 0; i < n; i++)
        // {
        //     if (a[i] == 1)
        //     {
        //         if (s[i] == 'L')
        //         {
        //             if (s[(i - 1 + n) % n] != 'R')
        //                 cnt++;

        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //         else if (s[i] == 'R')
        //         {
        //             if (s[(i + 1) % n] != 'L')
        //                 cnt++;
        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //     }
        // }

        // cout << (cnt / 2) << endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        cin >> n;
        string s;

        cin >> s;
        n = s.size();

        // int a[n] = {0};

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
                // a[(i - 1 + n) % n]++;
            }
            else
            {
                if (Rindex == -1)
                    Rindex = i;
                // a[(i + 1) % n]++;
            }
        }

        if (Rindex == -1 or Lindex == -1)               // If string contains only 'L' or only 'R' then this
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;
        }
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)                      // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                    if (s[i] == 'R')
                        cnt++;
                }

                if (s[i] == 'L')                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                {
                    cnt--;
                }

                ans += (cnt / 3);                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
                ans += (cnt % 3) / 2;            // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)

                // Now Checking consecutive L's   | Same above approach

                cnt = -1;                       // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)                 // If i have reached ending condition then consider the end element
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;              // analysing in segments of 3
                ans += (cnt % 3) / 2;

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        string s;

        if(t>1000)
        {
            while(1)
            {
                cin>>n;
                cin>>s;
                if(k==33)
                {
                    cout<<k<<endl;
                    cout<<n<<endl;
                    cout<<s<<endl;
                    return 0;
                }
                k++;
            }
        }

        cin>>n;
        cin >> s;
        n = s.size();

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
            }
            else
            {
                if (Rindex == -1 and Lindex!=-1)
                    Rindex = i;
            }
        }

        // My Logic:
        // for s='LLLLLL' -> LRL LRL  -> L RL L RL -> one L dropped and then a pair formed and repeat
        // for s='LLLLLLLL' -> LRL LRL LL -> LRL LRL RL ->  one L dropped and then a pair formed repeated
        //                                                  and at last 2 remained which got handled as special case using mod as u will see below

        // If string contains only 'L' or only 'R' then this
        if (Rindex == -1 or Lindex == -1)
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;     // I analyse in segments of size 3,
        }                                                  // E.g For s='LLLLL' -> LRL RL one 3 size segment and one 2 sizeed i.e remainder by mod 3
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                if (i == j)
                    if (s[i] == 'R')
                        cnt++;
                }

                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                if (s[i] == 'L')
                {
                    cnt--;
                }

                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
                // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)
                ans += (cnt / 3);
                ans += (cnt % 3) / 2;

                // Now Checking consecutive L's   | Same above approach
                // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                cnt = -1;
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;                // analysing in segments of 3
                ans += (cnt % 3) / 2;            // if a segment of length 2 remains then gotta change one more character

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        string s;

        // if(t>1000)
        // {
        //     while(1)
        //     {
        //         cin>>n;
        //         cin>>s;
        //         if(k==33)
        //         {
        //             cout<<k<<endl;
        //             cout<<n<<endl;
        //             cout<<s<<endl;
        //             return 0;
        //         }
        //         k++;
        //     }
        // }

        cin>>n;
        cin >> s;
        n = s.size();

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        int count=0;
        for (int i = 0; count <= 2*n; i=(i+1)%n)
        {
            count++;
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
            }
            else
            {
                if (Rindex == -1 and Lindex!=-1)
                    Rindex = i;
            }
        }

        // My Logic:
        // for s='LLLLLL' -> LRL LRL  -> L RL L RL -> one L dropped and then a pair formed and repeat
        // for s='LLLLLLLL' -> LRL LRL LL -> LRL LRL RL ->  one L dropped and then a pair formed repeated
        //                                                  and at last 2 remained which got handled as special case using mod as u will see below

        // If string contains only 'L' or only 'R' then this
        if (Rindex == -1 or Lindex == -1)
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;     // I analyse in segments of size 3,
        }                                                  // E.g For s='LLLLL' -> LRL RL one 3 size segment and one 2 sizeed i.e remainder by mod 3
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                if (i == j)
                    if (s[i] == 'R')
                        cnt++;
                }

                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                if (s[i] == 'L')
                {
                    cnt--;
                }

                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
                // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)
                ans += (cnt / 3);
                ans += (cnt % 3) / 2;

                // Now Checking consecutive L's   | Same above approach
                // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                cnt = -1;
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;                // analysing in segments of 3
                ans += (cnt % 3) / 2;            // if a segment of length 2 remains then gotta change one more character

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    test()
    {

        int n;
        // cin >> n;

        string s;
        cin >> s;
        n=s.size();

        int a[n] = {0};

        int f = -1;
        int li=-1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if(li==-1)
                    li=i;
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (f == -1)
                    f = i;
                a[(i + 1) % n]++;
            }
        }

        if (f == -1 or li==-1)
        {
            cout << n / 2 << endl;
        }
        else
        {

            int ans=0;

            int i=f;
            int j=(i-1+n)%n;

            while(i!=j)
            {
                int cnt=0;
                while(s[i]=='R' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='R')
                        cnt++;
                }
                if(s[i]=='L')
                {
                    cnt--;
                }
                ans+=(cnt/3);
                ans+=(cnt%3)/2;

                cnt=-1;
                while(s[i]=='L' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='L')
                        cnt++;
                }
                ans+=(cnt)/3;
                ans+=(cnt%3)/2;

            }

            cout<<ans<<endl;
        }

        int cnt = 0;
        // for (int i = 0; i < n; i++)
        // {
        //     if (a[i] == 1)
        //     {
        //         if (s[i] == 'L')
        //         {
        //             if (s[(i - 1 + n) % n] != 'R')
        //                 cnt++;

        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //         else if (s[i] == 'R')
        //         {
        //             if (s[(i + 1) % n] != 'L')
        //                 cnt++;
        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //     }
        // }

        // cout << (cnt / 2) << endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        cin >> n;
        string s;

        cin >> s;
        n = s.size();

        // int a[n] = {0};

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
                // a[(i - 1 + n) % n]++;
            }
            else
            {
                if (Rindex == -1)
                    Rindex = i;
                // a[(i + 1) % n]++;
            }
        }

        if (Rindex == -1 or Lindex == -1)           // If string contains only 'L' or only 'R' then this
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;
        }
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)                      // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                    if (s[i] == 'R')
                        cnt++;
                }

                if (s[i] == 'L')                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                {
                    cnt--;
                }

                ans += (cnt / 3);                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
                ans += (cnt % 3) / 2;            // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)

                // Now Checking consecutive L's   | Same above approach

                cnt = -1;                        // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)                      // If i have reached ending condition then consider the end element
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;                // analysing in segments of 3
                ans += (cnt % 3) / 2;            // if a segment of length 2 remains then gotta change one more character

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        cin >> n;
        string s;

        cin >> s;
        n = s.size();

        // int a[n] = {0};

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
                // a[(i - 1 + n) % n]++;
            }
            else
            {
                if (Rindex == -1)
                    Rindex = i;
                // a[(i + 1) % n]++;
            }
        }

        // My Logic:
        // for s='LLLLLL' -> LRL LRL  -> L RL L RL -> one L dropped and then a pair formed and repeat
        // for s='LLLLLLLL' -> LRL LRL LL -> LRL LRL RL ->  one L dropped and then a pair formed repeated
        //                                                  and at last 2 remained which got handled as special case using mod as u will see below

        if (Rindex == -1 or Lindex == -1)           // If string contains only 'L' or only 'R' then this
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;     // I analyse in segments of size 3,
        }                                                  // E.g For s='LLLLL' -> LRL RL one 3 size segment and one 2 sizeed i.e remainder by mod 3
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)                      // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                    if (s[i] == 'R')
                        cnt++;
                }

                if (s[i] == 'L')                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                {
                    cnt--;
                }

                ans += (cnt / 3);                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
                ans += (cnt % 3) / 2;            // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)

                // Now Checking consecutive L's   | Same above approach

                cnt = -1;                        // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)                      // If i have reached ending condition then consider the end element
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;                // analysing in segments of 3
                ans += (cnt % 3) / 2;            // if a segment of length 2 remains then gotta change one more character

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        string s;

        cin >> s;
        n = s.size();

        int a[n] = {0};

        int Rindex = -1;
        int Lindex = -1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (Rindex == -1)
                    Rindex = i;
                a[(i + 1) % n]++;
            }
        }

        if (Rindex == -1 or Lindex == -1)               // If string contains only 'L' or only 'R' then this
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;
        }
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {
                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                if (i == j)                      // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                    if (s[i] == 'R')
                        cnt++;
                }
                if (s[i] == 'L')                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                {
                    cnt--;
                }
                ans += (cnt / 3);                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so one changed
                ans += (cnt % 3) / 2;

                // Now Checking consecutive L's   | Same above approach
                cnt = -1;                          // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                if (i == j)
                {
                    if (s[i] == 'L')
                        cnt++;
                }
                ans += (cnt) / 3;
                ans += (cnt % 3) / 2;

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    test()
    {

        int n;
        cin >> n;

        string s;
        cin >> s;
        n=s.size();

        int a[n] = {0};

        int f = -1;
        int li=-1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if(li==-1)
                    li=i;
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (f == -1)
                    f = i;
                a[(i + 1) % n]++;
            }
        }

        if (f == -1 or li==-1)
        {
            cout << n / 2 << endl;
        }
        else
        {

            int ans=0;

            int i=f;
            int j=(i-1+n)%n;

            while(i!=j)
            {
                int cnt=0;
                while(s[i]=='R' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='R')
                        cnt++;
                }
                if(s[i]=='L')
                {
                    cnt--;
                }
                ans+=(cnt/3);
                ans+=(cnt%3)/2;

                cnt=-1;
                while(s[i]=='L' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='L')
                        cnt++;
                }
                ans+=(cnt)/3;
                ans+=(cnt%3)/2;

            }

            cout<<ans<<endl;
        }

        int cnt = 0;
        // for (int i = 0; i < n; i++)
        // {
        //     if (a[i] == 1)
        //     {
        //         if (s[i] == 'L')
        //         {
        //             if (s[(i - 1 + n) % n] != 'R')
        //                 cnt++;

        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //         else if (s[i] == 'R')
        //         {
        //             if (s[(i + 1) % n] != 'L')
        //                 cnt++;
        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //     }
        // }

        // cout << (cnt / 2) << endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin>>t;
    for(int k=1;k<=t;k++)
    {

        int n;
        string s;

        // cin >> n;

        if(t>1000)
        {
            while(1)
            {
                cin>>n;
                cin>>s;
                if(k==52)
                {
                    cout<<k<<endl;
                    cout<<n<<endl;
                    cout<<s<<endl;
                    return 0;
                }
                k++;
            }
        }

        cin>>n;

        cin >> s;
        n=s.size();

        int a[n] = {0};

        int f = -1;
        int li=-1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if(li==-1)
                    li=i;
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (f == -1)
                    f = i;
                a[(i + 1) % n]++;
            }
        }

        if (f == -1 or li==-1)
        {
            cout << n / 2 << endl;
        }
        else
        {

            int ans=0;

            int i=f;
            int j=(i-1+n)%n;

            while(i!=j)
            {
                int cnt=0;
                while(s[i]=='R' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='R')
                        cnt++;
                }
                if(s[i]=='L')
                {
                    cnt--;
                }
                ans+=(cnt/3);
                ans+=(cnt%3)/2;

                cnt=-1;
                while(s[i]=='L' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='L')
                        cnt++;
                }
                ans+=(cnt)/3;
                ans+=(cnt%3)/2;

            }

            cout<<ans<<endl;
        }

        int cnt = 0;
        // for (int i = 0; i < n; i++)
        // {
        //     if (a[i] == 1)
        //     {
        //         if (s[i] == 'L')
        //         {
        //             if (s[(i - 1 + n) % n] != 'R')
        //                 cnt++;

        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //         else if (s[i] == 'R')
        //         {
        //             if (s[(i + 1) % n] != 'L')
        //                 cnt++;
        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //     }
        // }

        // cout << (cnt / 2) << endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        string s;

        if(t>1000)
        {
            while(1)
            {
                cin>>n;
                cin>>s;
                if(k==33)
                {
                    cout<<k<<endl;
                    cout<<n<<endl;
                    cout<<s<<endl;
                    return 0;
                }
                k++;
            }
        }

        cin >> s;
        n = s.size();

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
            }
            else
            {
                if (Rindex == -1 and Lindex!=-1)
                    Rindex = i;
            }
        }

        // My Logic:
        // for s='LLLLLL' -> LRL LRL  -> L RL L RL -> one L dropped and then a pair formed and repeat
        // for s='LLLLLLLL' -> LRL LRL LL -> LRL LRL RL ->  one L dropped and then a pair formed repeated
        //                                                  and at last 2 remained which got handled as special case using mod as u will see below

        // If string contains only 'L' or only 'R' then this
        if (Rindex == -1 or Lindex == -1)
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;     // I analyse in segments of size 3,
        }                                                  // E.g For s='LLLLL' -> LRL RL one 3 size segment and one 2 sizeed i.e remainder by mod 3
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                if (i == j)
                    if (s[i] == 'R')
                        cnt++;
                }

                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                if (s[i] == 'L')
                {
                    cnt--;
                }

                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
                // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)
                ans += (cnt / 3);
                ans += (cnt % 3) / 2;

                // Now Checking consecutive L's   | Same above approach
                // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                cnt = -1;
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;                // analysing in segments of 3
                ans += (cnt % 3) / 2;            // if a segment of length 2 remains then gotta change one more character

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        cin>>n;
        string s;

        cin >> s;
        n = s.size();

        int a[n] = {0};

        int Rindex = -1;
        int Lindex = -1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (Rindex == -1)
                    Rindex = i;
                a[(i + 1) % n]++;
            }
        }

        if (Rindex == -1 or Lindex == -1)               // If string contains only 'L' or only 'R' then this
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;
        }
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {
                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                if (i == j)                      // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                    if (s[i] == 'R')
                        cnt++;
                }
                if (s[i] == 'L')                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                {
                    cnt--;
                }
                ans += (cnt / 3);                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so one changed
                ans += (cnt % 3) / 2;

                // Now Checking consecutive L's   | Same above approach
                cnt = -1;                          // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                if (i == j)
                {
                    if (s[i] == 'L')
                        cnt++;
                }
                ans += (cnt) / 3;
                ans += (cnt % 3) / 2;

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        cin >> n;
        string s;

        cin >> s;
        n = s.size();

        // int a[n] = {0};

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
                // a[(i - 1 + n) % n]++;
            }
            else
            {
                if (Rindex == -1 and Lindex!=-1)
                    Rindex = i;
                // a[(i + 1) % n]++;
            }
        }

        // My Logic:
        // for s='LLLLLL' -> LRL LRL  -> L RL L RL -> one L dropped and then a pair formed and repeat
        // for s='LLLLLLLL' -> LRL LRL LL -> LRL LRL RL ->  one L dropped and then a pair formed repeated
        //                                                  and at last 2 remained which got handled as special case using mod as u will see below

        // If string contains only 'L' or only 'R' then this
        if (Rindex == -1 or Lindex == -1)
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;     // I analyse in segments of size 3,
        }                                                  // E.g For s='LLLLL' -> LRL RL one 3 size segment and one 2 sizeed i.e remainder by mod 3
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                if (i == j)
                    if (s[i] == 'R')
                        cnt++;
                }

                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                if (s[i] == 'L')
                {
                    cnt--;
                }

                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
               // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)
                ans += (cnt / 3);
                ans += (cnt % 3) / 2;

                // Now Checking consecutive L's   | Same above approach
                // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                cnt = -1;
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;                // analysing in segments of 3
                ans += (cnt % 3) / 2;            // if a segment of length 2 remains then gotta change one more character

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin>>t;
    for(int k=1;k<=t;k++)
    {

        int n;
        string s;

        // cin >> n;

        if(t>1000)
        {
            while(1)
            {
                cin>>n;
                cin>>s;
                if(k==52)
                {
                    cout<<n<<endl;
                    cout<<s<<endl;
                    return 0;
                }
                k++;
            }
        }

        cin>>n;

        cin >> s;
        n=s.size();

        int a[n] = {0};

        int f = -1;
        int li=-1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if(li==-1)
                    li=i;
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (f == -1)
                    f = i;
                a[(i + 1) % n]++;
            }
        }

        if (f == -1 or li==-1)
        {
            cout << n / 2 << endl;
        }
        else
        {

            int ans=0;

            int i=f;
            int j=(i-1+n)%n;

            while(i!=j)
            {
                int cnt=0;
                while(s[i]=='R' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='R')
                        cnt++;
                }
                if(s[i]=='L')
                {
                    cnt--;
                }
                ans+=(cnt/3);
                ans+=(cnt%3)/2;

                cnt=-1;
                while(s[i]=='L' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='L')
                        cnt++;
                }
                ans+=(cnt)/3;
                ans+=(cnt%3)/2;

            }

            cout<<ans<<endl;
        }

        int cnt = 0;
        // for (int i = 0; i < n; i++)
        // {
        //     if (a[i] == 1)
        //     {
        //         if (s[i] == 'L')
        //         {
        //             if (s[(i - 1 + n) % n] != 'R')
        //                 cnt++;

        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //         else if (s[i] == 'R')
        //         {
        //             if (s[(i + 1) % n] != 'L')
        //                 cnt++;
        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //     }
        // }

        // cout << (cnt / 2) << endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
//###########################################//

int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin>>t;
    for(int k=1;k<=t;k++)
    {

        int n;
        string s;

        if(t>1000)
        {
            while(1)
            {
                cin>>n;
                cin>>s;
                if(k==64)
                {
                    cout<<k<<endl;
                    cout<<n<<endl;
                    cout<<s<<endl;
                    return 0;
                }
                k++;
            }
        }

        cin>>n;

        cin >> s;
        n=s.size();

        int a[n] = {0};

        int f = -1;
        int li=-1;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if(li==-1)
                    li=i;
                a[(i - 1 + n) % n]++;
            }
            else
            {
                if (f == -1)
                    f = i;
                a[(i + 1) % n]++;
            }
        }

        if (f == -1 or li==-1)
        {
            cout << (n/3 + (n%3+1)/2) << endl;
        }
        else
        {

            int ans=0;

            int i=f;
            int j=(i-1+n)%n;

            while(i!=j)
            {
                int cnt=0;
                while(s[i]=='R' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='R')
                        cnt++;
                }
                if(s[i]=='L')
                {
                    cnt--;
                }
                ans+=(cnt/3);
                ans+=(cnt%3)/2;

                cnt=-1;
                while(s[i]=='L' and i!=j)
                {
                    cnt++;
                    i=(i+1)%n;
                }
                if(i==j)
                {
                    if(s[i]=='L')
                        cnt++;
                }
                ans+=(cnt)/3;
                ans+=(cnt%3)/2;

            }

            cout<<ans<<endl;
        }

        int cnt = 0;
        // for (int i = 0; i < n; i++)
        // {
        //     if (a[i] == 1)
        //     {
        //         if (s[i] == 'L')
        //         {
        //             if (s[(i - 1 + n) % n] != 'R')
        //                 cnt++;

        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //         else if (s[i] == 'R')
        //         {
        //             if (s[(i + 1) % n] != 'L')
        //                 cnt++;
        //             // if ( s[(i + 1) % n] != 'L' and s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //             // else if (s[(i - 1 + n) % n] != 'R')
        //             //     cnt++;
        //         }
        //     }
        // }

        // cout << (cnt / 2) << endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

int debug = 1;
int test = 1;
#define ll long long
#define run if(debug){ cout<<__LINE__<<endl;}

//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

void filereader() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    filereader();

    test = 1;
    debug = 0;

    int t;
    cin >> t;
    for (int k = 1; k <= t; k++)
    {

        int n;
        cin >> n;
        string s;

        if(t>1000)
        {
            while(1)
            {
                cin>>n;
                cin>>s;
                if(k==33)
                {
                    cout<<k<<endl;
                    cout<<n<<endl;
                    cout<<s<<endl;
                    return 0;
                }
                k++;
            }
        }

        cin >> s;
        n = s.size();

        int Rindex = -1;        // To store first occurance of 'R'
        int Lindex = -1;        // To store first occurance of 'L'

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                if (Lindex == -1)
                    Lindex = i;
            }
            else
            {
                if (Rindex == -1 and Lindex!=-1)
                    Rindex = i;
            }
        }

        // My Logic:
        // for s='LLLLLL' -> LRL LRL  -> L RL L RL -> one L dropped and then a pair formed and repeat
        // for s='LLLLLLLL' -> LRL LRL LL -> LRL LRL RL ->  one L dropped and then a pair formed repeated
        //                                                  and at last 2 remained which got handled as special case using mod as u will see below

        // If string contains only 'L' or only 'R' then this
        if (Rindex == -1 or Lindex == -1)
        {
            cout << (n / 3 + (n % 3 + 1) / 2) << endl;     // I analyse in segments of size 3,
        }                                                  // E.g For s='LLLLL' -> LRL RL one 3 size segment and one 2 sizeed i.e remainder by mod 3
        else
        {

            int ans = 0;

            int i = Rindex;
            int j = (i - 1 + n) % n;

            while (i != j)
            {

                // Checking consecutive R's
                int cnt = 0;
                while (s[i] == 'R' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }
                // If i have reached end then gotta check if this is 'R' or not since this is last iteration
                {
                if (i == j)
                    if (s[i] == 'R')
                        cnt++;
                }

                 // If this is 'L' then i can make a pair 'RL' and hence discard one 'R' from consideration
                if (s[i] == 'L')
                {
                    cnt--;
                }

                // I analyse any consecutive segment in groups of 3, i.e RRRRRR-> RRR RR -> RRL RL so two 'R' got changed
                // Few more eg's -> For RRRRRR i will do -> RRL RRL -> R RL R RL  (2 changed ok)
                ans += (cnt / 3);
                ans += (cnt % 3) / 2;

                // Now Checking consecutive L's   | Same above approach
                // Here I start by cnt=-1 and not cnt=0 bcoz first 'L' is already paired up with prev 'R' so gotta discard first L
                cnt = -1;
                while (s[i] == 'L' and i != j)
                {
                    cnt++;
                    i = (i + 1) % n;
                }

                if (i == j)
                {
                    if (s[i] == 'L')
                        cnt++;
                }

                ans += (cnt) / 3;                // analysing in segments of 3
                ans += (cnt % 3) / 2;            // if a segment of length 2 remains then gotta change one more character

            }

            cout << ans << endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;

#define fo(i,n) for(int i = 0; i < n; i++)
#define parr(a,n) fo(i,n){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) fo(i,n)cin >> a[i]
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int, int> mi;
typedef map<long long, long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

// DEBUGGING
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/

ll n;

void solve() {
  cin >> n;
  string s; cin >> s;
  vi a(n,0);

  fo (i,n) {
    if (s[i] == 'L') a[((i-1)%n + n)%n]++;
    else a[(i+1)%n]++;
  }

  int cnt = 0;

  fo (i,n) {
    if (a[i] == 0 || a[i] == 2) continue;
    if (s[(i+1)%n] == 'L' && s[i] == 'L') {
      cnt++;
      s[i] = 'R';
      a[((i - 1) % n + n) % n]--;
      a[(i+1)%n]++;
      continue;
    }

    if (s[(i-1)%n] == 'R' && s[i] == 'R') {
      cnt++;
      s[i] = 'L';
      a[(i+1)%n]--;
      a[((i - 1) % n + n) % n]++;
      continue;
    }
  }

  cout << cnt << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

/*******************************************************/


#include<bits/stdc++.h>
using namespace std;

#define fo(i,n) for(int i = 0; i < n; i++)
#define parr(a,n) fo(i,n){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) fo(i,n)cin >> a[i]
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int, int> mi;
typedef map<long long, long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

// DEBUGGING
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/

ll n;

void solve() {
  cin >> n;
  string s; cin >> s;
  vi a(n, 0);

  fo(i, n) {
    if (s[i] == 'L') a[((i - 1) % n + n) % n]++;
    else a[(i + 1) % n]++;
  }

  int cnt = 0;
  int tmp = 0;
  char cur = 'N';
  fo(i, n) {
    if (s[i] == s[((i - 1) % n + n) % n] && s[i] == s[(i + 1) % n] && a[i] == 1) {
      if (cur == s[i]) tmp++;
      else {
        tmp = 1;
        cur = s[i];
      }
    } else {
      // debug(ceil((double)tmp / 3));
      cnt += (ceil((double)tmp / 3));
      tmp = 0;
      cur = 'N';
    }
    // debug(i, tmp);
  }
  if (tmp) cnt += ceil((double)tmp / 3);
  cout << cnt << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

/*******************************************************/


#include<bits/stdc++.h>
using namespace std;

#define fo(i,n) for(int i = 0; i < n; i++)
#define parr(a,n) fo(i,n){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) fo(i,n)cin >> a[i]
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int, int> mi;
typedef map<long long, long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

// DEBUGGING
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/

ll n;

void solve() {
  cin >> n;
  string s; cin >> s;
  vi a(n, 0);

  fo(i, n) {
    if (s[i] == 'L') a[((i - 1) % n + n) % n]++;
    else a[(i + 1) % n]++;
  }

  // debug(a);

  bool foundR = false, foundL = false;
  int firstR = -1, firstL = -1;
  fo(i, n) {
    if (s[i] == 'L') {
      foundL = 1;
      if (firstL == -1)firstL = i;
    }
    else {
      foundR = 1;
      if (firstR == -1)firstR = i;
    }

    if (foundL && foundR) break;

  }

  firstL = max(firstL, firstR);

  int cnt = 0;
  int tmp = 0;
  char cur = 'N';
  for (int i = firstL; i < n + firstL; i++) {
    if (s[i%n] == s[((i - 1) % n + n) % n] && s[i%n] == s[(i + 1) % n] && a[i%n] == 1) {
      if (cur == s[i%n]) tmp++;
      else {
        tmp = 1;
        cur = s[i%n];
      }
    }
    else {
    // debug(i, tmp);
      // debug(ceil((double)tmp / 3));
      if (tmp) cnt += (tmp / 3 + (tmp%3 != 0));
      tmp = 0;
      cur = 'N';
    }
  }
  if (tmp) cnt += ceil((double)tmp / 3);
  cout << cnt << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

/*******************************************************/


#include<bits/stdc++.h>
using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define FO(i, j) FOR(i, 0, j, 1)
#define RFO(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int,int> mi;
typedef map<long long,long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

template<typename... T>
void read(T&... args) {
  ((cin >> args), ...);
}

template<typename... T>
void write(T&&... args) {
  ((cout << args << " "), ...);
}

#define MOD 1000000007
int mpow(int, int);
/*******************************************************/

ll n;

void solve() {
  read(n);
  string s; read(s);
  int cnt;
  int ans = 0;

  FO(i,n) {
    if (s[((i-1)%n+n)%n] == s[i] && s[i] == s[(i+1)%n]) {
      ans++;
      if (s[i] == 'R') s[i] = 'L';
      else s[i] = 'R';
    }
  }

  // FO(i, n) {
  //   cnt = 0;
  //   if (i == 0) {
  //     cnt = (s[n-1] == 'R') + (s[1] == 'L');
  //     if (cnt == 1) {
  //       if (s[n-1] == 'R' && s[0] == 'R') {
  //         ans++;
  //         s[0] = 'L';
  //       }
  //       else if (s[1] == 'L' && s[0] == 'L') {
  //         ans++;
  //         s[0] = 'R';
  //       }
  //     }
  //   } else if (i == n-1) {
  //     cnt = (s[n-2] == 'R') + (s[0] == 'L');
  //     if (cnt == 1) {
  //      if (s[n-2] == 'R' && s[i] == 'R') {
  //         ans++;
  //         s[i] = 'L';
  //       }
  //       else if (s[0] == 'L' && s[i] == 'L') {
  //         ans++;
  //         s[i] = 'R';
  //       }
  //     }
  //   } else {
  //     cnt = (s[i-1] == 'R') + (s[i+1] == 'L');
  //     if (cnt == 1) {
  //      if (s[i-1] == 'R' && s[i] == 'R') {
  //         ans++;
  //         s[i] = 'L';
  //       }
  //       else if (s[i+1] == 'L' && s[i] == 'L') {
  //         ans++;
  //         s[i] = 'R';
  //       }
  //     }
  //   }
  // }

  cout << ans << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while(t--) {
    solve();
  }

  return 0;
}

/*******************************************************/
int mpow(int base, int exp) {
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % MOD;
    base = ((ll)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}


#include<bits/stdc++.h>
using namespace std;

#define fo(i,n) for(int i = 0; i < n; i++)
#define parr(a,n) fo(i,n){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) fo(i,n)cin >> a[i]
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int, int> mi;
typedef map<long long, long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

// DEBUGGING
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/

ll n;

void solve() {
  cin >> n;
  string s; cin >> s;
  // vi a(n, 0);

  // fo(i, n) {
  //   if (s[i] == 'L') a[((i - 1) % n + n) % n]++;
  //   else a[(i + 1) % n]++;
  // }

  // debug(a);

  int cnt = 0;
  int tmp = 0;
  char cur = 'N';
  fo(i, n) {
    // if (s[i] == s[((i - 1) % n + n) % n] && s[i] == s[(i + 1) % n]) {
    if (s[i] == s[(i + 1) % n]) {
      if (cur == s[i]) tmp++;
      else {
        tmp = 2;
        cur = s[i];
      }
    }
    else {
      // debug(ceil((double)tmp / 3));
      cnt += (tmp / 3);
      tmp = 0;
      cur = 'N';
    }
    // debug(i, tmp);
  }
  if (tmp) cnt += (tmp / 3);

  cout << cnt << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

/*******************************************************/


#include<bits/stdc++.h>
using namespace std;

#define fo(i,n) for(int i = 0; i < n; i++)
#define parr(a,n) fo(i,n){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) fo(i,n)cin >> a[i]
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int, int> mi;
typedef map<long long, long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

// DEBUGGING
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/

ll n;

void solve() {
  cin >> n;
  string s; cin >> s;
  // vi a(n, 0);
  bool foundR = false, foundL = false;
  int firstR = -1, firstL = -1;
  fo(i, n) {
    if (s[i] == 'L') {
      foundL = 1;
      if (firstL == -1)firstL = i;
    } else {
      foundR = 1;
      if (firstR == -1)firstR = i;
    }

    if (foundL && foundR) break;

  }

  if (foundL ^ foundR) {
    cout << n/3 + (n%3 != 0) << "\n";
    return;
  }

  firstL = (firstL)?firstL:firstR;

  // debug(a);
  int cnt = 0;
  int tmp = 0;
  char cur = 'N';
  for(int i = firstL; i < n + firstL; i++) {
    // if (s[i] == s[((i - 1) % n + n) % n] && s[i] == s[(i + 1) % n]) {
    if (s[i%n] == s[(i + 1) % n]) {
      if (cur == s[i%n]) tmp++;
      else {
        tmp = 2;
        cur = s[i%n];
      }
    }
    else {
      // debug(ceil((double)tmp / 3));
      cnt += (tmp / 3);
      tmp = 0;
      cur = 'N';
    }
  }

  if (tmp) cnt += (tmp / 3);

  cout << cnt << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

/*******************************************************/


#include<bits/stdc++.h>
using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define FO(i, j) FOR(i, 0, j, 1)
#define RFO(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int,int> mi;
typedef map<long long,long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

template<typename... T>
void read(T&... args) {
  ((cin >> args), ...);
}

template<typename... T>
void write(T&&... args) {
  ((cout << args << " "), ...);
}

#define MOD 1000000007
int mpow(int, int);
/*******************************************************/

ll n;

void solve() {
  read(n);
  string s; read(s);
  int cnt;
  int ans = 0;
string s1 = s;
  FO(i,n) {
    if (s[((i-1)%n+n)%n] == s[i] && s[i] == s[((i-2)%n+n)%n]) {
      ans++;
      if (s[(i+1)%n] != s[i]) {
        if (s[((i-1)%n+n)%n] == 'R') s[((i-1)%n+n)%n] = 'L';
        else s[((i-1)%n+n)%n] = 'R';

      } else {

        if (s[i] == 'R') s[i] = 'L';
        else s[i] = 'R';
      }
    }
  }

  // int ans2 = 0;
  // s = s1;
  // FO(i,n) {
  //   if (s[((i-1)%n+n)%n] == s[i] && s[i] == s[(i+1)%n]) {
  //     ans2++;
  //     if (s[i] == 'R') s[i] = 'L';
  //     else s[i] = 'R';
  //   }
  // }

  // FO(i, n) {
  //   cnt = 0;
  //   if (i == 0) {
  //     cnt = (s[n-1] == 'R') + (s[1] == 'L');
  //     if (cnt == 1) {
  //       if (s[n-1] == 'R' && s[0] == 'R') {
  //         ans++;
  //         s[0] = 'L';
  //       }
  //       else if (s[1] == 'L' && s[0] == 'L') {
  //         ans++;
  //         s[0] = 'R';
  //       }
  //     }
  //   } else if (i == n-1) {
  //     cnt = (s[n-2] == 'R') + (s[0] == 'L');
  //     if (cnt == 1) {
  //      if (s[n-2] == 'R' && s[i] == 'R') {
  //         ans++;
  //         s[i] = 'L';
  //       }
  //       else if (s[0] == 'L' && s[i] == 'L') {
  //         ans++;
  //         s[i] = 'R';
  //       }
  //     }
  //   } else {
  //     cnt = (s[i-1] == 'R') + (s[i+1] == 'L');
  //     if (cnt == 1) {
  //      if (s[i-1] == 'R' && s[i] == 'R') {
  //         ans++;
  //         s[i] = 'L';
  //       }
  //       else if (s[i+1] == 'L' && s[i] == 'L') {
  //         ans++;
  //         s[i] = 'R';
  //       }
  //     }
  //   }
  // }

  // cout << min(ans2,ans) << "\n";
  cout << ans << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while(t--) {
    solve();
  }

  return 0;
}

/*******************************************************/
int mpow(int base, int exp) {
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % MOD;
    base = ((ll)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}


#include<bits/stdc++.h>
using namespace std;

#define fo(i,n) for(int i = 0; i < n; i++)
#define parr(a,n) fo(i,n){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) fo(i,n)cin >> a[i]
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int, int> mi;
typedef map<long long, long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

// DEBUGGING
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/

ll n;

void solve() {
  cin >> n;
  string s; cin >> s;
  // vi a(n, 0);

  // fo(i, n) {
  //   if (s[i] == 'L') a[((i - 1) % n + n) % n]++;
  //   else a[(i + 1) % n]++;
  // }

  // debug(a);
  bool foundR = false, foundL = false;
  int cnt = 0;
  int tmp = 0;
  char cur = 'N';
  fo(i, n) {
    if (s[i] == 'L') foundL = 1;
    if (s[i] == 'R') foundR = 1;
    // if (s[i] == s[((i - 1) % n + n) % n] && s[i] == s[(i + 1) % n]) {
    if (s[i] == s[(i + 1) % n]) {
      if (cur == s[i]) tmp++;
      else {
        tmp = 2;
        cur = s[i];
      }
    }
    else {
      // debug(ceil((double)tmp / 3));
      cnt += (tmp / 3);
      tmp = 0;
      cur = 'N';
    }
    // debug(i, tmp);
  }

  if (tmp) cnt += (tmp / 3);

  if (foundL ^ foundR) {
    cnt = n/3 + (n%3 != 0);
  }

  cout << cnt << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

/*******************************************************/


#include<bits/stdc++.h>
using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define FO(i, j) FOR(i, 0, j, 1)
#define RFO(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<pi> vpii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int,int> mi;
typedef map<long long,long long> ml;
typedef set<int> si;
typedef set<long long> sl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

template<typename... T>
void read(T&... args) {
  ((cin >> args), ...);
}

template<typename... T>
void write(T&&... args) {
  ((cout << args << " "), ...);
}

#define MOD 1000000007
int mpow(int, int);
/*******************************************************/

ll n;

void solve() {
  read(n);
  string s; read(s);
  int cnt;
  int ans = 0;
  FO(i, n) {
    cnt = 0;
    if (i == 0) {
      cnt = (s[n-1] == 'R') + (s[1] == 'L');
      if (cnt == 1) {
        if (s[n-1] == 'R' && s[0] == 'R') {
          ans++;
          s[0] = 'L';
        }
        else if (s[1] == 'L' && s[0] == 'L') {
          ans++;
          s[0] = 'R';
        }
      }
    } else if (i == n-1) {
      cnt = (s[n-2] == 'R') + (s[0] == 'L');
      if (cnt == 1) {
       if (s[n-2] == 'R' && s[i] == 'R') {
          ans++;
          s[i] = 'L';
        }
        else if (s[0] == 'L' && s[i] == 'L') {
          ans++;
          s[i] = 'R';
        }
      }
    } else {
      cnt = (s[i-1] == 'R') + (s[i+1] == 'L');
      if (cnt == 1) {
       if (s[i-1] == 'R' && s[i] == 'R') {
          ans++;
          s[i] = 'L';
        }
        else if (s[i+1] == 'L' && s[i] == 'L') {
          ans++;
          s[i] = 'R';
        }
      }
    }
  }

  cout << ans << "\n";
}

int main() {
  IO();

  int t = 1;
  cin >> t;
  while(t--) {
    solve();
  }

  return 0;
}

/*******************************************************/
int mpow(int base, int exp) {
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % MOD;
    base = ((ll)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}