import java.io.*;
import java.util.*;

public class DD {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int t = Integer.parseInt(buffer.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(buffer.readLine());
            char[]s = new char[n+2];
            String inp = buffer.readLine();
            for (int i = 0; i < inp.length(); i++) {
                s[i] = inp.charAt(i);
            }
            s[n] = s[0];
            s[n+1] = s[1];
            int cnt = 0;
//            System.out.println(Arrays.toString(s));
            for (int pos = 0; pos < s.length-2; pos++) {
                String temp = s[pos] +Character.toString(s[pos+1])+ s[pos + 2];
                boolean checkR = temp.equals("RRR"), checkL = temp.equals("LLL");
                if (pos+4 < s.length && (checkL||checkR)){
                    String temp2 = s[pos+2] +Character.toString(s[pos+3])+ s[pos + 4];
                    if (temp2.equals(temp))
                        if (checkR) {
                            s[pos + 2] = 'L';
                            cnt++;
                        }
                        else {
                            s[pos + 2] = 'R';
                            cnt++;
                        }
                }
                temp = s[pos] +Character.toString(s[pos+1])+ s[pos + 2];
                if (temp.equals("RRR")) {
                    s[pos + 1] = 'L';
                    cnt++;
                }
                else if (temp.equals("LLL")) {
                    s[pos + 1] = 'R';
                    cnt++;
                }
            }
//            System.out.println(Arrays.toString(s));
            sb.append(cnt+"\n");
        }
        System.out.println(sb);
    }
}


import java.io.*;
import java.util.*;

public class DD {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int t = Integer.parseInt(buffer.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(buffer.readLine());
            char[]s = new char[n+2];
            String inp = buffer.readLine();
            for (int i = 0; i < inp.length(); i++) {
                s[i] = inp.charAt(i);
            }
            s[n] = s[0];
            s[n+1] = s[1];
            int cnt = 0;
//            System.out.println(Arrays.toString(s));
            for (int pos = 0; pos < s.length-1; pos++) {
                if (s[pos]==s[pos+1]){
                    int temp = 1;
                    while (pos < s.length-1 && s[pos]==s[pos+1]){
                        temp++;
                        pos++;
                    }
                    cnt += temp/3;
                }
            }
//            System.out.println(Arrays.toString(s));
            sb.append(cnt+"\n");
        }
        System.out.println(sb);
    }
}


import java.io.*;
import java.util.*;

public class DD {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int t = Integer.parseInt(buffer.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(buffer.readLine());
            char[]s = new char[n+2];
            String inp = buffer.readLine();
            for (int i = 0; i < inp.length(); i++) {
                s[i] = inp.charAt(i);
            }
            s[n] = s[0];
            s[n+1] = s[1];
            int cnt = 0;
//            System.out.println(Arrays.toString(s));
            for (int pos = 0; pos < s.length-3; pos++) {
                String temp = s[pos] +Character.toString(s[pos+1])+ s[pos + 2];
                if (temp.equals("RRR")) {
                    s[pos + 1] = 'L';
                    cnt++;
                }
                else if (temp.equals("LLL")) {
                    s[pos + 1] = 'R';
                    cnt++;
                }

            }
            sb.append(cnt+"\n");
        }
        System.out.println(sb);
    }
}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = in.nextInt();
        for(int t = 1; t <= tests; t++) {
            int n = in.nextInt();
            String s = in.next();
            int[] A = new int[n];
            for(int i = 0; i < n; i++) {
                if(s.charAt(i) == 'L') {
                    A[i] = 0;
                } else {
                    A[i] = 1;
                }
            }
            if(n == 3) {
                if(s.equals("LLL") ||s.equals("RRR")) {
                    System.out.println(1);
                } else {
                    System.out.println(0);
                }
                return;
            }

            int[][] dp = new int[n][2]; //0 for L, 1 for R
            int ans = (int) 1e9;
            for(int i = 0; i < 2; i++) {
                for(int j = 0; j < 2; j++) {
                    int cost = Math.abs(A[0] - i) + Math.abs(A[1] - j);
                    //i == 0 means first letter is supposed to be L
                    dp[0][0] = i == 0 ? 0 : n;
                    dp[0][1] = n - dp[0][0];
                    dp[1][0] = j == 0 ? 0 : n;
                    dp[1][1] = n - dp[1][0];

                    for(int k = 2; k < n-1; k++) {
                        dp[k][0] = A[k] + Math.min(dp[k-1][1], A[k-1] + dp[k-2][1]);
                        dp[k][1] = 1-A[k] + Math.min(dp[k-1][0], (1-A[k-1]) + dp[k-2][0]);
                    }

                    if(i == j) {
                        dp[n-1][0] = A[i] + Math.min(dp[n-2][1], A[n-2] + dp[n-3][1]);
                        dp[n-1][1] = 1-A[i] + Math.min(dp[n-2][0], (1-A[n-2]) + dp[n-3][0]);
                        cost += dp[n-1][1-i];
                    } else {
                        dp[n-1][i] = Math.abs(A[n-1] - i) + dp[n-2][1-i];
                        dp[n-1][1-i] = Math.abs(A[n-1]  - (1-i)) + Math.min(dp[n-2][i],
                                                            Math.abs((1-i) - A[n-2]) + dp[n-3][i]);
                        cost += Math.min(dp[n-1][0], dp[n-1][1]);
                    }
                    ans = Math.min(ans, cost);
                    //System.out.println("COST: "  + cost);
                    for(int k = 0; k < 2; k++) {
                        for(int l = 0; l < n; l++) {
                            //System.out.print(dp[l][k] + " ");
                        }
                        //System.out.println();
                    }
                }
            }
            System.out.println(ans);

        }

    }

}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = in.nextInt();
        for(int t = 1; t <= tests; t++) {
            int n = in.nextInt();
            String s = in.next();
            int[] A = new int[n];
            for(int i = 0; i < n; i++) {
                if(s.charAt(i) == 'L') {
                    A[i] = 0;
                } else {
                    A[i] = 1;
                }
            }
            if(n == 3) {
                if(s.equals("LLL") ||s.equals("RRR")) {
                    System.out.println(1);
                } else {
                    System.out.println(0);
                }
                return;
            }

            int[][] dp = new int[n][2]; //0 for L, 1 for R
            int ans = (int) 1e9;
            for(int i = 0; i < 2; i++) {
                for(int j = 0; j < 2; j++) {
                    int cost = Math.abs(A[0] - i) + Math.abs(A[1] - j);
                    //i == 0 means first letter is supposed to be L
                    dp[0][0] = i == 0 ? 0 : n;
                    dp[0][1] = n - dp[0][0];
                    dp[1][0] = j == 0 ? 0 : n;
                    dp[1][1] = n - dp[1][0];

                    for(int k = 2; k < n-1; k++) {
                        dp[k][0] = A[k] + Math.min(dp[k-1][1], A[k-1] + dp[k-2][1]);
                        dp[k][1] = 1-A[k] + Math.min(dp[k-1][0], (1-A[k-1]) + dp[k-2][0]);
                    }

                    if(i == j) {
                        dp[n-1][0] = A[n-1] + Math.min(dp[n-2][1], A[n-2] + dp[n-3][1]);
                        dp[n-1][1] = 1-A[n-1] + Math.min(dp[n-2][0], (1-A[n-2]) + dp[n-3][0]);
                        cost += dp[n-1][1-i];
                    } else {
                        dp[n-1][i] = Math.abs(A[n-1] - i) + dp[n-2][1-i];
                        dp[n-1][1-i] = Math.abs(A[n-1]  - (1-i)) + Math.min(dp[n-2][i],
                                                            Math.abs((1-i) - A[n-2]) + dp[n-3][i]);
                        cost += Math.min(dp[n-1][0], dp[n-1][1]);
                    }
                    ans = Math.min(ans, cost);
                    //System.out.println("COST: "  + cost);
                    for(int k = 0; k < 2; k++) {
                        for(int l = 0; l < n; l++) {
                            //System.out.print(dp[l][k] + " ");
                        }
                        //System.out.println();
                    }
                }
            }
            System.out.println(ans);
        }
    }
}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = in.nextInt();
        for(int secret = 1; secret <= tests; secret++) {
            int n = in.nextInt();
            String s = in.next();
            int[] A = new int[n];
            for(int i = 0; i < n; i++) {
                if(s.charAt(i) == 'L') {
                    A[i] = 0;
                } else {
                    A[i] = 1;
                }
            }
            if(n == 3) {
                if(s.equals("LLL") ||s.equals("RRR")) {
                    System.out.println(1);
                } else {
                    System.out.println(0);
                }
                return;
            }

            int[][] dp = new int[n][2]; //0 for L, 1 for R
            int ans = (int) 1e9;
            for(int i = 0; i < 2; i++) {
                for(int j = 0; j < 2; j++) {
                    int cost = Math.abs(A[0] - i) + Math.abs(A[1] - j);
                    //i == 0 means first letter is supposed to be L
                    dp[0][0] = i == 0 ? 0 : n;
                    dp[0][1] = n - dp[0][0];
                    dp[1][0] = j == 0 ? 0 : n;
                    dp[1][1] = n - dp[1][0];

                    for(int k = 2; k < n-1; k++) {
                        dp[k][0] = A[k] + Math.min(dp[k-1][1], A[k-1] + dp[k-2][1]);
                        dp[k][1] = 1-A[k] + Math.min(dp[k-1][0], (1-A[k-1]) + dp[k-2][0]);
                    }

                    if(i == j) {
                        dp[n-1][0] = A[n-1] + Math.min(dp[n-2][1], A[n-2] + dp[n-3][1]);
                        dp[n-1][1] = 1-A[n-1] + Math.min(dp[n-2][0], (1-A[n-2]) + dp[n-3][0]);
                        cost += dp[n-1][1-i];
                    } else {
                        dp[n-1][i] = Math.abs(A[n-1] - i) + dp[n-2][1-i];
                        dp[n-1][1-i] = Math.abs(A[n-1]  - (1-i)) + Math.min(dp[n-2][i],
                                                            Math.abs((1-i) - A[n-2]) + dp[n-3][i]);
                        cost += Math.min(dp[n-1][0], dp[n-1][1]);
                    }
                    ans = Math.min(ans, cost);
                    //System.out.println("COST: "  + cost);
                    for(int k = 0; k < 2; k++) {
                        for(int l = 0; l < n; l++) {
                            //System.out.print(dp[l][k] + " ");
                        }
                        //System.out.println();
                    }
                }
            }
            System.out.println(ans);
        }
    }
}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = in.nextInt();
        for(int t = 1; t <= tests; t++) {
            int n = in.nextInt();
            String s = in.next();
            int[] A = new int[n];
            for(int i = 0; i < n; i++) {
                if(s.charAt(i) == 'L') {
                    A[i] = 0;
                } else {
                    A[i] = 1;
                }
            }
            if(n == 3) {
                if(s.equals("LLL") ||s.equals("RRR")) {
                    System.out.println(1);
                } else {
                    System.out.println(0);
                }
                return;
            }

            int[][] dp = new int[n][2]; //0 for L, 1 for R
            int ans = (int) 1e9;
            for(int i = 0; i < 2; i++) {
                for(int j = 0; j < 2; j++) {
                    int cost = Math.abs(A[0] - i) + Math.abs(A[1] - j);
                    //i == 0 means first letter is supposed to be L
                    dp[0][0] = i == 0 ? 0 : n;
                    dp[0][1] = n - dp[0][0];
                    dp[1][0] = j == 0 ? 0 : n;
                    dp[1][1] = n - dp[1][0];

                    for(int k = 2; k < n-1; k++) {
                        dp[k][0] = A[k] + Math.min(dp[k-1][1], A[k-1] + dp[k-2][1]);
                        dp[k][1] = 1-A[k] + Math.min(dp[k-1][0], (1-A[k-1]) + dp[k-2][0]);
                    }

                    if(i == j) {
                        dp[n-1][0] = A[n-1] + Math.min(dp[n-2][1], A[n-2] + dp[n-3][1]);
                        dp[n-1][1] = 1-A[n-1] + Math.min(dp[n-2][0], (1-A[n-2]) + dp[n-3][0]);
                        cost += dp[n-1][1-i];
                    } else {
                        dp[n-1][i] = Math.abs(A[n-1] - i) + dp[n-2][1-i];
                        dp[n-1][1-i] = Math.abs(A[n-1]  - (1-i)) + Math.min(dp[n-2][i],
                                                            Math.abs((1-i) - A[n-2]) + dp[n-3][i]);
                        cost += Math.min(dp[n-1][0], dp[n-1][1]);
                    }
                    ans = Math.min(ans, cost);
                    //System.out.println("COST: "  + cost);
                    for(int k = 0; k < 2; k++) {
                        for(int l = 0; l < n; l++) {
                            //System.out.print(dp[l][k] + " ");
                        }
                        //System.out.println();
                    }
                }
            }
            System.out.println(ans);

        }

    }

}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = in.nextInt();
        for(int secret = 1; secret <= tests; secret++) {
            int n = in.nextInt();
            String s = in.next();

            int ans = solve(n, s);
            System.out.println(ans);

        }
    }

    private static int solve(int n, String s) {
        int[] A = new int[n];
        for(int i = 0; i < n; i++) {
            if(s.charAt(i) == 'L') {
                A[i] = 0;
            } else {
                A[i] = 1;
            }
        }
        if(n == 3) {
            if(s.equals("LLL") ||s.equals("RRR")) {
                return 1;
            } else {
                return 0;
            }
        }

        int[][] dp = new int[n][2]; //0 for L, 1 for R
        int ans = (int) 1e9;
        for(int i = 0; i < 2; i++) {
            for(int j = 0; j < 2; j++) {
                int cost = Math.abs(A[0] - i) + Math.abs(A[1] - j);
                //i == 0 means first letter is supposed to be L
                dp[0][0] = i == 0 ? 0 : n;
                dp[0][1] = n - dp[0][0];
                dp[1][0] = j == 0 ? 0 : n;
                dp[1][1] = n - dp[1][0];

                for(int k = 2; k < n-1; k++) {
                    dp[k][0] = A[k] + Math.min(dp[k-1][1], A[k-1] + dp[k-2][1]);
                    dp[k][1] = 1-A[k] + Math.min(dp[k-1][0], (1-A[k-1]) + dp[k-2][0]);
                }

                if(i == j) {
                    dp[n-1][0] = A[n-1] + Math.min(dp[n-2][1], A[n-2] + dp[n-3][1]);
                    dp[n-1][1] = 1-A[n-1] + Math.min(dp[n-2][0], (1-A[n-2]) + dp[n-3][0]);
                    cost += dp[n-1][1-i];
                } else {
                    dp[n-1][i] = Math.abs(A[n-1] - i) + dp[n-2][1-i];
                    dp[n-1][1-i] = Math.abs(A[n-1]  - (1-i)) + Math.min(dp[n-2][i],
                            Math.abs((1-i) - A[n-2]) + dp[n-3][i]);
                    cost += Math.min(dp[n-1][0], dp[n-1][1]);
                }
                ans = Math.min(ans, cost);
                //System.out.println("COST: "  + cost);
                for(int k = 0; k < 2; k++) {
                    for(int l = 0; l < n; l++) {
                        //System.out.print(dp[l][k] + " ");
                    }
                    //System.out.println();
                }
            }
        }
        return ans;
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();
            char prev = c[0];
            int count = 1;
            long sum = 0;
            boolean first = true;
            long val = 0;
            boolean run = false;
            for (int i = 1; i < n; i++) {
                if (c[i] == prev) {
                    count++;
                    if (i == n - 1 && c[0] != prev) {
                        sum += count / 3 + val / 3;
                        run = true;
                    }
                    if (i == n - 1 && c[0] == prev) {
                        sum += (count + val) / 3;
                        run = true;
                    }
                } else {
                    if (first)
                        val = count;
                    prev = c[i];
                    if (!first)
                        sum += count / 3;
                    first = false;
                    count = 1;
                }
            }
            if (!run) {
                sum += val / 3;
            }

            if (count == n) {
                sum = (long) Math.ceil((double) n / 3);
            }
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();
            long count = 0;
            for (int i = 0; i < n; i++) {
                char l, r;
                if (i == 0) {
                    l = c[n - 1];
                } else {
                    l = c[i - 1];
                }
                if (i == n - 1) {
                    r = c[0];
                } else {
                    r = c[i + 1];
                }
                // No attack
                if (l == 'L' && r == 'R') {
                    continue;
                    // One attack
                } else if (l == 'L' && r == 'L') {
                    if (c[i] != 'R') {
                        c[i] = 'R';
                        count++;
                    }
                } else if (l == 'R' && r == 'R') {
                    if (c[i] != 'L') {
                        c[i] = 'L';
                        count++;
                    }
                    // Two attack
                }
            }
            sb.append(count).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();
            int count = 0;
            char prev = '0';
            long sum = 0;
            for (int i = 0; i < n; i++) {
                if (c[i] == prev) {
                    count++;
                    if (i == n - 1 && c[0] != prev) {
                        sum += count / 3;
                    }
                    if (i == n - 1 && c[0] == prev) {
                        sum += (count + 1) / 3;
                    }
                } else {
                    prev = c[i];
                    sum += count / 3;
                    count = 1;
                }
            }

            if (count == n) {
                sum = (long) Math.ceil((double) n / 3);
            }
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();
            char prev = c[0];
            int count = 1;
            long sum = 0;
            boolean first = true;
            long val = 0;
            boolean run = false;
            for (int i = 1; i < n; i++) {
                if (c[i] == prev) {
                    count++;
                    if (i == n - 1 && c[0] != prev) {
                        sum += count / 3 + val / 3;
                        run = true;
                    }
                    if (i == n - 1 && c[0] == prev) {
                        sum += (count + val) / 3;
                        run = true;
                    }
                } else {
                    if (first)
                        val = count;
                    prev = c[i];
                    if (!first)
                        sum += count / 3;
                    first = false;
                    count = 1;
                    if (i == n - 1 && c[0] == prev) {
                        sum += (count + val) / 3;
                        run = true;
                    }
                }
            }
            if (!run) {
                sum += val / 3;
            }

            if (count == n) {
                sum = (long) Math.ceil((double) n / 3);
            }
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();
            int count = 0;
            char prev = '0';
            long sum = 0;
            for (int i = 0; i < n; i++) {
                if (c[i] == prev) {
                    count++;
                    if (i == n - 1 && c[0] != prev) {
                        sum += count / 3;
                    }
                    if (i == n - 1 && c[0] == prev) {
                        sum += (count + 1) / 3;
                    }
                } else {
                    prev = c[i];
                    sum += count / 3;
                    count = 1;
                }
            }

            if (count == n) {
                sum = (n + 2) / 3;
            }
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();

            long min = Integer.MAX_VALUE;
            for (int start = 0; start < n; start++) {
                long count = 0;
                char c[] = str.toCharArray();
                for (int i = start; i < n; i++) {
                    char l, r;
                    if (i % 2 == 0) {
                        l = c[n - 1];
                    } else {
                        l = c[i - 1];
                    }
                    if (i == n - 1) {
                        r = c[0];
                    } else {
                        r = c[i + 1];
                    }
                    // No attack
                    if (l == 'L' && r == 'R') {
                        continue;
                        // One attack
                    } else if (l == 'L' && r == 'L') {
                        if (c[i] != 'R') {
                            c[i] = 'R';
                            count++;
                        }
                    } else if (l == 'R' && r == 'R') {
                        if (c[i] != 'L') {
                            c[i] = 'L';
                            count++;
                        }
                        // Two attack
                    }
                }
                for (int i = 0; i < start; i++) {
                    char l, r;
                    if (i % 2 == 0) {
                        l = c[n - 1];
                    } else {
                        l = c[i - 1];
                    }
                    if (i == n - 1) {
                        r = c[0];
                    } else {
                        r = c[i + 1];
                    }
                    // No attack
                    if (l == 'L' && r == 'R') {
                        continue;
                        // One attack
                    } else if (l == 'L' && r == 'L') {
                        if (c[i] != 'R') {
                            c[i] = 'R';
                            count++;
                        }
                    } else if (l == 'R' && r == 'R') {
                        if (c[i] != 'L') {
                            c[i] = 'L';
                            count++;
                        }
                        // Two attack
                    }
                }
                min = Math.min(min, count);
            }
            sb.append(min).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();

            long count = 0;
            long min = Integer.MAX_VALUE;
            for (int start = 0; start < n; start++) {
                for (int i = start; i < n; i++) {
                    char l, r;
                    if (i % 2 == 0) {
                        l = c[n - 1];
                    } else {
                        l = c[i - 1];
                    }
                    if (i == n - 1) {
                        r = c[0];
                    } else {
                        r = c[i + 1];
                    }
                    // No attack
                    if (l == 'L' && r == 'R') {
                        continue;
                        // One attack
                    } else if (l == 'L' && r == 'L') {
                        if (c[i] != 'R') {
                            c[i] = 'R';
                            count++;
                        }
                    } else if (l == 'R' && r == 'R') {
                        if (c[i] != 'L') {
                            c[i] = 'L';
                            count++;
                        }
                        // Two attack
                    }
                }
                for (int i = 0; i < start; i++) {
                    char l, r;
                    if (i % 2 == 0) {
                        l = c[n - 1];
                    } else {
                        l = c[i - 1];
                    }
                    if (i == n - 1) {
                        r = c[0];
                    } else {
                        r = c[i + 1];
                    }
                    // No attack
                    if (l == 'L' && r == 'R') {
                        continue;
                        // One attack
                    } else if (l == 'L' && r == 'L') {
                        if (c[i] != 'R') {
                            c[i] = 'R';
                            count++;
                        }
                    } else if (l == 'R' && r == 'R') {
                        if (c[i] != 'L') {
                            c[i] = 'L';
                            count++;
                        }
                        // Two attack
                    }
                }
                min = Math.min(min, count);
            }
            sb.append(min).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();
            int count = 0;
            char prev = '0';
            long sum = 0;
            for (int i = 0; i < n; i++) {
                if (c[i] == prev) {
                    count++;
                    if (i == n - 1 && c[0] != prev && count != n) {
                        sum += count / 3;
                    }
                    if (i == n - 1 && c[0] == prev && count != n) {
                        sum += (count + 1) / 3;
                    }
                } else {
                    prev = c[i];
                    sum += count / 3;
                    count = 1;
                }
            }

            if (count == n) {
                sum = (long) Math.ceil((double) n / 3);
            }
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();
            int count = 0;
            char prev = '0';
            long sum = 0;
            for (int i = 0; i < n; i++) {
                if (c[i] == prev) {
                    count++;
                    if (i == n - 1 && c[0] != prev && count != n - 1) {
                        sum += count / 3;
                    }
                    if (i == n - 1 && c[0] == prev && count != n - 1) {
                        sum += (count + 1) / 3;
                    }
                } else {
                    prev = c[i];
                    sum += count / 3;
                    count = 1;
                }
            }

            if (count == n) {
                sum = (long) Math.ceil((double) n / 3);
            }
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            sc.nextLine();
            String str = sc.nextLine();
            char c[] = str.toCharArray();
            char prev = c[0];
            int count = 1;
            long sum = 0;
            boolean first = true;
            long val = 0;
            for (int i = 1; i < n; i++) {
                if (c[i] == prev) {
                    count++;
                    if (i == n - 1 && c[0] != prev) {
                        sum += count / 3 + val / 3;
                    }
                    if (i == n - 1 && c[0] == prev) {
                        sum += (count + val) / 3;
                    }
                } else {
                    if (first)
                        val = count;
                    prev = c[i];
                    if (!first)
                        sum += count / 3;
                    first = false;
                    count = 1;
                }
            }

            if (count == n) {
                sum = (long) Math.ceil((double) n / 3);
            }
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
}


import java.io.*;
import java.util.*;

public class D {
static class Pair<E, V> implements Comparable<Pair<E, V>>{
       E a;
       V b;
       public Pair(E x, V y) {a = x;b=y;}
       public int compareTo(Pair<E, V> p){
           return Integer.compare((Integer)a, (Integer)p.a);
       }
//        @Override
//        public int hashCode() {
//            final int prime = 31;
//            int result = 1;
//            result = prime * result + (Integer)a;
//            result = prime * result + (Integer)b;
//
//            return result;
//        }
//        @Override
//        public boolean equals(Object obj) {
//            Pair<E, V> cur = (Pair<E, V>)obj;
//            if((Integerx)a == (Integer)cur.a && (Integer)b == (Integer)cur.b)return true;
//            if((Integer)b == (Integer)cur.a && (Integer)a == (Integer)cur.b)return true;
//            return false;
//        }
 }
static class cols implements Comparable<cols>{
	int ind, val, orig;
	public cols(int ind, int val, int orig) {
		this.ind = ind;
		this.val = val;
		this.orig = orig;
	}
	public int compareTo(cols c) {
		return -Integer.compare(val, c.val);
	}
}
public static void main(String[] args){
   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
public static long gcd(long a,long b)
{
  if(a<b)
    return gcd(b,a);
  if(b==0)
    return a;
  return gcd(b,a%b);

}
static long lcm(int a,int b) {
  return  a*b / gcd(a,b);
}
static int[] z(char[]arr) {
    int l = 0, r = 0;
    int[]z = new int[n];
    for(int i=1; i<n; i++) {
        if(i > r) {
            l = r = i;
            while(r < n && arr[r-l] == arr[r])r++;
            z[i] = r-- - l;
        }else {
            int k = i - l;
            if(z[k] < r - i + l)z[i] = z[k];
            else {
                l = i;
                while(r < n && arr[r-l] == arr[r])r++;
                z[i] = r-- - l;
            }
        }
    }
    return z;
}
static long pow(long x,long y){
    if(y == 0)return 1;
    if(y==1)return x;
    long a = pow(x,y/2);
    a = (a*a)%mod;
    if(y%2==0){
        return a;
    }
    return (a*x)%mod;
}
static long my_inv(long a) {
    return pow(a,mod-2);
}
static long bin(int a,int b) {
    if(a < b || a<0 || b<0)return 0;
    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
}
static void make_facts() {
  fact=new long[mxN];
  inv_fact = new long[mxN];
  fact[0]=inv_fact[0]=1L;
  for(int i=1;i<mxN;i++) {
       fact[i] = (i*fact[i-1])%mod;
//       inv_fact[i] = my_inv(fact[i]);
  }
}
static final long mxx = (long)(1e18+5);
static final int mxN = (int)(4e5+5);
static final int mxV = (int)(1e5+5), log = 18;
static long mod = (long)(1e9+7); //998244353;//̇
static long[]fact, inv_fact;
static final int INF = (int)1e9;
static boolean[][]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, q, x, y, z, d;
static char[]str;
static int[]arr;
static int R, G, B;
static long ans = 0;
static Integer[][][]dp;
static int rec(int i, int prev, int first) {
	if(i == n-1) {
		if(arr[i] == prev && arr[i] == first)return 1;
		return 0;
	}
	if(dp[i][prev][first] != null)return dp[i][prev][first];
	if(arr[i] == prev && arr[i+1] == arr[i]) {
		return dp[i][prev][first] = rec(i+1, arr[i] ^ 1, first) + 1;
	}
	return dp[i][prev][first] = rec(i+1, arr[i], first);
//	int o2 = rec(i+1, arr[i] ^ 1, first) + 1;
//	return dp[i][prev][first] = Math.min(o1, o2);

}
public static void solve() throws Exception {
	   // solve the problem here
			s = new MyScanner();
	   		out = new PrintWriter(new BufferedOutputStream(System.out), true);
//	   		out = new PrintWriter("output.txt");
	        int tc = s.nextInt();
	        while(tc-->0){
	        	n = s.nextInt();
	        	str = s.next().toCharArray();
	        	arr = new int[2*n];
	        	for(int i=0; i<n; i++) {
	        		arr[i] = str[i] == 'R' ? 1 : 0;
	        	}
	        	for(int i=n; i<2*n; i++) {
	        		arr[i] = str[i-n] == 'R' ? 1 : 0;
	        	}
	        	dp = new Integer[n+1][2][2];
	        	int ans = Math.min(rec(1, arr[0], arr[0]), rec(1, arr[0] ^ 1, arr[0] ^ 1) + 1);
	        	out.println(ans);
	        }

	        out.flush();
	        out.close();
	}

public static PrintWriter out;
public static MyScanner s;
static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    public MyScanner(String fileName) {
    	try {
			br = new BufferedReader(new FileReader(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
    }
    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()); }
    int[] nextIntArray(int n){
    	int[]a = new int[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    long[] nextlongArray(int n) {
    	long[]a = new long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    Integer[] nextIntegerArray(int n){
    	Integer[]a = new Integer[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    Long[] nextLongArray(int n) {
    	Long[]a = new Long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    char[][] next2DCharArray(int n, int m){
    	char[][]arr = new char[n][m];
    	for(int i=0; i<n; i++) {
    		arr[i] = this.next().toCharArray();
    	}
    	return arr;
    }
    ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    		adj.get(v).add(u);
    	}
    	return adj;
    }
    ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    	}
    	return adj;
    }
    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

}


import java.io.*;
import java.util.*;

public class D {
static class Pair<E, V> implements Comparable<Pair<E, V>>{
       E a;
       V b;
       public Pair(E x, V y) {a = x;b=y;}
       public int compareTo(Pair<E, V> p){
           return Integer.compare((Integer)a, (Integer)p.a);
       }
//        @Override
//        public int hashCode() {
//            final int prime = 31;
//            int result = 1;
//            result = prime * result + (Integer)a;
//            result = prime * result + (Integer)b;
//
//            return result;
//        }
//        @Override
//        public boolean equals(Object obj) {
//            Pair<E, V> cur = (Pair<E, V>)obj;
//            if((Integerx)a == (Integer)cur.a && (Integer)b == (Integer)cur.b)return true;
//            if((Integer)b == (Integer)cur.a && (Integer)a == (Integer)cur.b)return true;
//            return false;
//        }
 }
static class cols implements Comparable<cols>{
	int ind, val, orig;
	public cols(int ind, int val, int orig) {
		this.ind = ind;
		this.val = val;
		this.orig = orig;
	}
	public int compareTo(cols c) {
		return -Integer.compare(val, c.val);
	}
}
public static void main(String[] args){
   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
public static long gcd(long a,long b)
{
  if(a<b)
    return gcd(b,a);
  if(b==0)
    return a;
  return gcd(b,a%b);

}
static long lcm(int a,int b) {
  return  a*b / gcd(a,b);
}
static int[] z(char[]arr) {
    int l = 0, r = 0;
    int[]z = new int[n];
    for(int i=1; i<n; i++) {
        if(i > r) {
            l = r = i;
            while(r < n && arr[r-l] == arr[r])r++;
            z[i] = r-- - l;
        }else {
            int k = i - l;
            if(z[k] < r - i + l)z[i] = z[k];
            else {
                l = i;
                while(r < n && arr[r-l] == arr[r])r++;
                z[i] = r-- - l;
            }
        }
    }
    return z;
}
static long pow(long x,long y){
    if(y == 0)return 1;
    if(y==1)return x;
    long a = pow(x,y/2);
    a = (a*a)%mod;
    if(y%2==0){
        return a;
    }
    return (a*x)%mod;
}
static long my_inv(long a) {
    return pow(a,mod-2);
}
static long bin(int a,int b) {
    if(a < b || a<0 || b<0)return 0;
    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
}
static void make_facts() {
  fact=new long[mxN];
  inv_fact = new long[mxN];
  fact[0]=inv_fact[0]=1L;
  for(int i=1;i<mxN;i++) {
       fact[i] = (i*fact[i-1])%mod;
//       inv_fact[i] = my_inv(fact[i]);
  }
}
static final long mxx = (long)(1e18+5);
static final int mxN = (int)(4e5+5);
static final int mxV = (int)(1e5+5), log = 18;
static long mod = (long)(1e9+7); //998244353;//̇
static long[]fact, inv_fact;
static final int INF = (int)1e9;
static boolean[][]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, q, x, y, z, d;
static char[]str;
static int[]arr;
static int R, G, B;
static long ans = 0;
static Integer[][][][][]dp;
static boolean works(int a, int b, int c) {
	// if all equal doesnt work
	return !(a == b && b == c);
}
static int rec(int i, int secprev, int prev, int first, int second) {
	if(i == n) {
		if(!works(secprev, prev, first))return INF;
		if(!works(prev, first, second))return INF;
		return 0;
	}
	if(dp[secprev][prev][first][second][i] != null)return dp[secprev][prev][first][second][i];
	int o1=INF, o2 = INF;
	if(works(secprev, prev, arr[i])) {
		o1 = rec(i+1, prev, arr[i], first, second);
	}
	if(works(secprev, prev, arr[i] ^ 1)) {
		o2 = rec(i+1, prev, arr[i] ^ 1, first, second) + 1;
	}
	return dp[secprev][prev][first][second][i] = Math.min(o1, o2);

}
static int cost(int x, int y) {
	int cnt = 0;
	if(arr[0] != x)cnt++;
	if(arr[1] != y)cnt++;
	return cnt;
}
public static void solve() throws Exception {
	   // solve the problem here
			s = new MyScanner();
	   		out = new PrintWriter(new BufferedOutputStream(System.out), true);
//	   		out = new PrintWriter("output.txt");
	        int tc = s.nextInt();
	        while(tc-->0){
	        	n = s.nextInt();
	        	str = s.next().toCharArray();
	        	arr = new int[n];
	        	for(int i=0; i<n; i++) {
	        		arr[i] = str[i] == 'R' ? 1 : 0;
	        	}
	        	dp = new Integer[2][2][2][2][n+1];
	        	int o1 = rec(2, 0, 0, 0, 0) + cost(0, 0);
	        	int o2 = rec(2, 1, 0, 1, 0) + cost(1, 0);
	        	int o3 = rec(2, 0, 1, 0, 1) + cost(0, 1);
	        	int o4 = rec(2, 1, 1, 1, 1) + cost(1, 1);
	        	int ans = Math.min(Math.min(o1, o2), Math.min(o3, o4));
	        	out.println(ans);
	        }

	        out.flush();
	        out.close();
	}

public static PrintWriter out;
public static MyScanner s;
static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    public MyScanner(String fileName) {
    	try {
			br = new BufferedReader(new FileReader(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
    }
    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()); }
    int[] nextIntArray(int n){
    	int[]a = new int[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    long[] nextlongArray(int n) {
    	long[]a = new long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    Integer[] nextIntegerArray(int n){
    	Integer[]a = new Integer[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    Long[] nextLongArray(int n) {
    	Long[]a = new Long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    char[][] next2DCharArray(int n, int m){
    	char[][]arr = new char[n][m];
    	for(int i=0; i<n; i++) {
    		arr[i] = this.next().toCharArray();
    	}
    	return arr;
    }
    ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    		adj.get(v).add(u);
    	}
    	return adj;
    }
    ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    	}
    	return adj;
    }
    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

}


import java.io.*;
import java.util.*;

public class D {
static class Pair<E, V> implements Comparable<Pair<E, V>>{
       E a;
       V b;
       public Pair(E x, V y) {a = x;b=y;}
       public int compareTo(Pair<E, V> p){
           return Integer.compare((Integer)a, (Integer)p.a);
       }
//        @Override
//        public int hashCode() {
//            final int prime = 31;
//            int result = 1;
//            result = prime * result + (Integer)a;
//            result = prime * result + (Integer)b;
//
//            return result;
//        }
//        @Override
//        public boolean equals(Object obj) {
//            Pair<E, V> cur = (Pair<E, V>)obj;
//            if((Integerx)a == (Integer)cur.a && (Integer)b == (Integer)cur.b)return true;
//            if((Integer)b == (Integer)cur.a && (Integer)a == (Integer)cur.b)return true;
//            return false;
//        }
 }
static class cols implements Comparable<cols>{
	int ind, val, orig;
	public cols(int ind, int val, int orig) {
		this.ind = ind;
		this.val = val;
		this.orig = orig;
	}
	public int compareTo(cols c) {
		return -Integer.compare(val, c.val);
	}
}
public static void main(String[] args){
   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
public static long gcd(long a,long b)
{
  if(a<b)
    return gcd(b,a);
  if(b==0)
    return a;
  return gcd(b,a%b);

}
static long lcm(int a,int b) {
  return  a*b / gcd(a,b);
}
static int[] z(char[]arr) {
    int l = 0, r = 0;
    int[]z = new int[n];
    for(int i=1; i<n; i++) {
        if(i > r) {
            l = r = i;
            while(r < n && arr[r-l] == arr[r])r++;
            z[i] = r-- - l;
        }else {
            int k = i - l;
            if(z[k] < r - i + l)z[i] = z[k];
            else {
                l = i;
                while(r < n && arr[r-l] == arr[r])r++;
                z[i] = r-- - l;
            }
        }
    }
    return z;
}
static long pow(long x,long y){
    if(y == 0)return 1;
    if(y==1)return x;
    long a = pow(x,y/2);
    a = (a*a)%mod;
    if(y%2==0){
        return a;
    }
    return (a*x)%mod;
}
static long my_inv(long a) {
    return pow(a,mod-2);
}
static long bin(int a,int b) {
    if(a < b || a<0 || b<0)return 0;
    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
}
static void make_facts() {
  fact=new long[mxN];
  inv_fact = new long[mxN];
  fact[0]=inv_fact[0]=1L;
  for(int i=1;i<mxN;i++) {
       fact[i] = (i*fact[i-1])%mod;
//       inv_fact[i] = my_inv(fact[i]);
  }
}
static final long mxx = (long)(1e18+5);
static final int mxN = (int)(4e5+5);
static final int mxV = (int)(1e5+5), log = 18;
static long mod = (long)(1e9+7); //998244353;//̇
static long[]fact, inv_fact;
static final int INF = (int)1e9;
static boolean[][]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, q, x, y, z, d;
static char[]str;
static int[]arr;
static int R, G, B;
static long ans = 0;
static Integer[][][][]dp;
static boolean works(int a, int b, int c) {
	// if all equal doesnt work
	return !(a == b && b == c);
}
static int rec(int i, int secprev, int prev, int first) {
	if(i == n) {
		if(!works(secprev, prev, first))return INF;
		return 0;
	}
	if(dp[secprev][prev][first][i] != null)return dp[secprev][prev][first][i];
	int o1=INF, o2 = INF;
	if(works(secprev, prev, arr[i])) {
		o1 = rec(i+1, prev, arr[i], first);
	}
	if(works(secprev, prev, arr[i] ^ 1)) {
		o2 = rec(i+1, prev, arr[i] ^ 1, first) + 1;
	}
	return dp[secprev][prev][first][i] = Math.min(o1, o2);

}
static int cost(int x, int y) {
	int cnt = 0;
	if(arr[0] != x)cnt++;
	if(arr[1] != y)cnt++;
	return cnt;
}
public static void solve() throws Exception {
	   // solve the problem here
			s = new MyScanner();
	   		out = new PrintWriter(new BufferedOutputStream(System.out), true);
//	   		out = new PrintWriter("output.txt");
	        int tc = s.nextInt();
	        while(tc-->0){
	        	n = s.nextInt();
	        	str = s.next().toCharArray();
	        	arr = new int[2*n];
	        	for(int i=0; i<n; i++) {
	        		arr[i] = str[i] == 'R' ? 1 : 0;
	        	}
	        	for(int i=n; i<2*n; i++) {
	        		arr[i] = str[i-n] == 'R' ? 1 : 0;
	        	}
	        	dp = new Integer[2][2][2][n+1];
	        	int o1 = rec(2, 0, 0, 0) + cost(0, 0);
	        	int o2 = rec(2, 1, 0, 1) + cost(1, 0);
	        	int o3 = rec(2, 0, 1, 0) + cost(0, 1);
	        	int o4 = rec(2, 1, 1, 1) + cost(1, 1);
	        	int ans = Math.min(Math.min(o1, o2), Math.min(o3, o4));
	        	out.println(ans);
	        }

	        out.flush();
	        out.close();
	}

public static PrintWriter out;
public static MyScanner s;
static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    public MyScanner(String fileName) {
    	try {
			br = new BufferedReader(new FileReader(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
    }
    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()); }
    int[] nextIntArray(int n){
    	int[]a = new int[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    long[] nextlongArray(int n) {
    	long[]a = new long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    Integer[] nextIntegerArray(int n){
    	Integer[]a = new Integer[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    Long[] nextLongArray(int n) {
    	Long[]a = new Long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    char[][] next2DCharArray(int n, int m){
    	char[][]arr = new char[n][m];
    	for(int i=0; i<n; i++) {
    		arr[i] = this.next().toCharArray();
    	}
    	return arr;
    }
    ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    		adj.get(v).add(u);
    	}
    	return adj;
    }
    ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    	}
    	return adj;
    }
    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

}


import java.io.*;
import java.util.*;

public class D {
static class Pair<E, V> implements Comparable<Pair<E, V>>{
       E a;
       V b;
       public Pair(E x, V y) {a = x;b=y;}
       public int compareTo(Pair<E, V> p){
           return Integer.compare((Integer)a, (Integer)p.a);
       }
//        @Override
//        public int hashCode() {
//            final int prime = 31;
//            int result = 1;
//            result = prime * result + (Integer)a;
//            result = prime * result + (Integer)b;
//
//            return result;
//        }
//        @Override
//        public boolean equals(Object obj) {
//            Pair<E, V> cur = (Pair<E, V>)obj;
//            if((Integerx)a == (Integer)cur.a && (Integer)b == (Integer)cur.b)return true;
//            if((Integer)b == (Integer)cur.a && (Integer)a == (Integer)cur.b)return true;
//            return false;
//        }
 }
static class cols implements Comparable<cols>{
	int ind, val, orig;
	public cols(int ind, int val, int orig) {
		this.ind = ind;
		this.val = val;
		this.orig = orig;
	}
	public int compareTo(cols c) {
		return -Integer.compare(val, c.val);
	}
}
public static void main(String[] args){
   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
public static long gcd(long a,long b)
{
  if(a<b)
    return gcd(b,a);
  if(b==0)
    return a;
  return gcd(b,a%b);

}
static long lcm(int a,int b) {
  return  a*b / gcd(a,b);
}
static int[] z(char[]arr) {
    int l = 0, r = 0;
    int[]z = new int[n];
    for(int i=1; i<n; i++) {
        if(i > r) {
            l = r = i;
            while(r < n && arr[r-l] == arr[r])r++;
            z[i] = r-- - l;
        }else {
            int k = i - l;
            if(z[k] < r - i + l)z[i] = z[k];
            else {
                l = i;
                while(r < n && arr[r-l] == arr[r])r++;
                z[i] = r-- - l;
            }
        }
    }
    return z;
}
static long pow(long x,long y){
    if(y == 0)return 1;
    if(y==1)return x;
    long a = pow(x,y/2);
    a = (a*a)%mod;
    if(y%2==0){
        return a;
    }
    return (a*x)%mod;
}
static long my_inv(long a) {
    return pow(a,mod-2);
}
static long bin(int a,int b) {
    if(a < b || a<0 || b<0)return 0;
    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
}
static void make_facts() {
  fact=new long[mxN];
  inv_fact = new long[mxN];
  fact[0]=inv_fact[0]=1L;
  for(int i=1;i<mxN;i++) {
       fact[i] = (i*fact[i-1])%mod;
//       inv_fact[i] = my_inv(fact[i]);
  }
}
static final long mxx = (long)(1e18+5);
static final int mxN = (int)(4e5+5);
static final int mxV = (int)(1e5+5), log = 18;
static long mod = (long)(1e9+7); //998244353;//̇
static long[]fact, inv_fact;
static final int INF = (int)1e9;
static boolean[][]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, q, x, y, z, d;
static char[]str;
static int[]arr;
static int R, G, B;
static long ans = 0;
static Integer[][][]dp;
static int rec(int i, int prev, int first) {
	if(i == n-1) {
		if(arr[i] == prev && arr[i] == first)return 1;
		return 0;
	}
	if(dp[i][prev][first] != null)return dp[i][prev][first];
	if(arr[i] == prev && arr[i+1] == arr[i]) {
		return dp[i][prev][first] = rec(i+1, arr[i] ^ 1, first) + 1;
	}
	int o1 = rec(i+1, arr[i], first);
	int o2 = rec(i+1, arr[i] ^ 1, first) + 1;
	return dp[i][prev][first] = Math.min(o1, o2);

}
public static void solve() throws Exception {
	   // solve the problem here
			s = new MyScanner();
	   		out = new PrintWriter(new BufferedOutputStream(System.out), true);
//	   		out = new PrintWriter("output.txt");
	        int tc = s.nextInt();
	        while(tc-->0){
	        	n = s.nextInt();
	        	str = s.next().toCharArray();
	        	arr = new int[2*n];
	        	for(int i=0; i<n; i++) {
	        		arr[i] = str[i] == 'R' ? 1 : 0;
	        	}
	        	for(int i=n; i<2*n; i++) {
	        		arr[i] = str[i-n] == 'R' ? 1 : 0;
	        	}
	        	dp = new Integer[n+1][2][2];
	        	int ans = Math.min(rec(1, arr[0], arr[0]), rec(1, arr[0] ^ 1, arr[0] ^ 1) + 1);
	        	out.println(ans);
	        }

	        out.flush();
	        out.close();
	}

public static PrintWriter out;
public static MyScanner s;
static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    public MyScanner(String fileName) {
    	try {
			br = new BufferedReader(new FileReader(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
    }
    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()); }
    int[] nextIntArray(int n){
    	int[]a = new int[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    long[] nextlongArray(int n) {
    	long[]a = new long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    Integer[] nextIntegerArray(int n){
    	Integer[]a = new Integer[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    Long[] nextLongArray(int n) {
    	Long[]a = new Long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    char[][] next2DCharArray(int n, int m){
    	char[][]arr = new char[n][m];
    	for(int i=0; i<n; i++) {
    		arr[i] = this.next().toCharArray();
    	}
    	return arr;
    }
    ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    		adj.get(v).add(u);
    	}
    	return adj;
    }
    ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    	}
    	return adj;
    }
    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

}


import java.io.*;
import java.util.*;

public class One {
    static int mod = 1000000007;
    public static void main(String[] args) {
        FastReader in = new FastReader();
        int t = in.nextInt();
        while(t-- > 0){
            int n = in.nextInt();
            String s = in.nextLine();
            int allSame = 1;
            for(int i = 0; i + 1 < n; i++){
                if(s.charAt(i) != s.charAt(i + 1)){
                    allSame = 0;
                    break;
                }
            }
            if(allSame == 1){
                System.out.println((n + 2) / 3);    //If all the characters in s are the same, then we can see similarly that Omkar needs to talk to ⌈n3⌉ of the players. (Note that we are rounding up instead of down  — this is due to the circular nature of s).
            }
            ArrayList<Integer> subSegmentsWithSameCharCount = new ArrayList<>();
            int ptr = 0;
            int cnt = 1;
            for(int i = 1; i < n; i++){
                if(s.charAt(i) == s.charAt(ptr)){
                    cnt++;
                }
                else {
                    subSegmentsWithSameCharCount.add(cnt);
                    ptr = i;
                    cnt = 1;
                }
            }
            if(s.charAt(0) == s.charAt(s.length() - 1)){
                subSegmentsWithSameCharCount.set(0, subSegmentsWithSameCharCount.get(0) + cnt);
            } else {
                subSegmentsWithSameCharCount.add(cnt);
            }
            int res = 0;
            for(int count : subSegmentsWithSameCharCount){
                res += count / 3;
            }
            System.out.println(res);
        }
    }

    static int getDigitSum(int n)
    {
        int sum = 0;

        while (n != 0)
        {
            sum = sum + n % 10;
            n = n/10;
        }

        return sum;
    }
    static int countSetBits(int n)
    {
        int count = 0;
        while (n > 0) {
            count += n & 1;
            n >>= 1;
        }
        return count;
    }
    static int gcd(int a, int b){
        if(b == 0){
            return a;
        }
        return gcd(b, a % b);
    }

    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;
        }
        int[] readArray(int n){
            int[] a = new int[n];
            for(int i = 0; i < n; i++){
                a[i] = nextInt();
            }
            return a;
        }
    }
}


import java.io.*;
import java.util.*;

public class One {
    static int mod = 1000000007;
    public static void main(String[] args) {
        FastReader in = new FastReader();
        int t = in.nextInt();
        while(t-- > 0){
            int n = in.nextInt();
            String s = in.nextLine();
            int allSame = 1;
            for(int i = 0; i + 1 < n; i++){
                if(s.charAt(i) != s.charAt(i + 1)){
                    allSame = 0;
                    break;
                }
            }
            if(allSame == 1){
                System.out.println((n + 2) / 3);    //If all the characters in s are the same, then we can see similarly that Omkar needs to talk to ⌈n3⌉ of the players. (Note that we are rounding up instead of down  — this is due to the circular nature of s).
                continue;
            }
            ArrayList<Integer> subSegmentsWithSameCharCount = new ArrayList<>();
            int ptr = 0;
            int cnt = 1;
            for(int i = 1; i < n; i++){
                if(s.charAt(i) == s.charAt(ptr)){
                    cnt++;
                }
                else {
                    subSegmentsWithSameCharCount.add(cnt);
                    ptr = i;
                    cnt = 1;
                }
            }
            if(s.charAt(0) == s.charAt(s.length() - 1)){
                subSegmentsWithSameCharCount.set(0, subSegmentsWithSameCharCount.get(0) + cnt);
            } else {
                subSegmentsWithSameCharCount.add(cnt);
            }
            int res = 0;
            for(int count : subSegmentsWithSameCharCount){
                res += count / 3;
            }
            System.out.println(res);
        }
    }

    static int getDigitSum(int n)
    {
        int sum = 0;

        while (n != 0)
        {
            sum = sum + n % 10;
            n = n/10;
        }

        return sum;
    }
    static int countSetBits(int n)
    {
        int count = 0;
        while (n > 0) {
            count += n & 1;
            n >>= 1;
        }
        return count;
    }
    static int gcd(int a, int b){
        if(b == 0){
            return a;
        }
        return gcd(b, a % b);
    }

    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;
        }
        int[] readArray(int n){
            int[] a = new int[n];
            for(int i = 0; i < n; i++){
                a[i] = nextInt();
            }
            return a;
        }
    }
}


import java.util.*;
import java.io.*;

public class A {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-->0) {
			int n = sc.nextInt();
			String str =sc.next();
			StringBuilder s = new StringBuilder(str);
                int c=0;
			for(int i=1;i<s.length()-1;i++){
			 if(s.charAt(i-1)=='R' &&  s.charAt(i)=='R' && s.charAt(i+1)=='R')
			 {
			       s.setCharAt(i, 'L');
			       c++;
			 }
			 else if(s.charAt(i-1)=='L' &&  s.charAt(i)=='L' && s.charAt(i+1)=='L'){
			       s.setCharAt(i, 'R');
			       c++;
			 }
			 else if((i+1)==(n-1) && s.charAt(i-1)=='L' &&  s.charAt(i)=='R' && s.charAt(i+1)=='R'){
			      if(s.charAt(0)=='R'){
			            s.setCharAt(i+1, 'L');
			            c++;
			      }
			 }
			  else if(i==1 && s.charAt(i-1)=='L' &&  s.charAt(i)=='L' && s.charAt(i+1)=='R'){
			      if(s.charAt(n-1)=='R'){
			            s.setCharAt(i-1, 'R');
			            c++;
			      }
			 }
			 else if((i+1)==(n-1) &&  s.charAt(i)=='L' && s.charAt(i+1)=='L' ){
			      if(s.charAt(0)=='L'){
			            s.setCharAt(i+1, 'R');
			            c++;
			      }
			 }
			 else if((i+1)==(n-1) &&  s.charAt(i)=='R' && s.charAt(i+1)=='R' ){
			      if(s.charAt(0)=='R'){
			            s.setCharAt(i+1, 'L');
			            c++;
			      }
			 }
			}
			System.out.println(c);
		}
	}
}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new  Scanner(System.in);
		int tc = s.nextInt();
		for(int t = 0;t < tc;t++) {
			int n = s.nextInt();
			char[] ch = s.next().toCharArray();
			boolean flag = false;
			for(int i = 0;i < ch.length;i++) {
				if(ch[i] != ch[0]) {
					flag = true;
					break;
				}
			}
			if(!flag) {
				System.out.println((n + 2) / 3);
			}
			else {
				ArrayList<Integer> arr = new ArrayList<>();
				boolean cont = false;
				int cnt = 0;
				int i = 0;
				int last = 0;
				while(i < n) {
					if(ch[last] == ch[i]) {
						cnt++;
					}
					else {
						arr.add(cnt);
						cnt = 1;
						last = i;
					}
					i++;
				}
				int ans = 0;
				if(ch[0] == ch[n - 1]) {
					arr.set(0, arr.get(0) + cnt);
				}
				else {
					arr.add(cnt);
				}
				for(int i1 : arr) {
					ans += i1/3;
				}
				System.out.println(ans);
			}
		}
	}

}


import java.util.*;
import java.io.*;

public class A {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-->0) {
			int n = sc.nextInt();
			String str =sc.next();
			StringBuilder s = new StringBuilder(str);
                int c=0;
			for(int i=1;i<s.length()-1;i++){
			 if(s.charAt(i-1)=='R' &&  s.charAt(i)=='R' && s.charAt(i+1)=='R')
			 {
			       s.setCharAt(i+1, 'L');
			       c++;
			 }
			 else if(s.charAt(i-1)=='L' &&  s.charAt(i)=='L' && s.charAt(i+1)=='L'){
			       s.setCharAt(i+1, 'R');
			       c++;
			 }

			 else if((i+1)==(n-1) &&  s.charAt(i)=='L' && s.charAt(i+1)=='L' ){
			      if(s.charAt(0)=='L'){
			            s.setCharAt(0, 'R');
			            c++;
			      }
			 }
			 else if((i+1)==(n-1) &&  s.charAt(i)=='R' && s.charAt(i+1)=='R' ){
			      if(s.charAt(0)=='R'){
			            s.setCharAt(0, 'L');
			            c++;
			      }
			 }
			}
			System.out.println(c);
		}
	}
}


/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */

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

public class Main
{
   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;
      }

      int[] readArray(int n, int size){
         int[] a = new int[size];
         for(int i = 0; i < n; i++) {
            a[i] = this.nextInt();
         }

         return a;
      }

      long[] readLongArray(int n, int size){
         long[] a = new long[size];
         for(int i = 0; i < n; i++) {
            a[i] = this.nextLong();
         }
         return a;
      }
   }

   public static void main(String[] args) {
      FastReader s=new FastReader();
      int t = s.nextInt();

      for(int z = 0; z < t; z++) {

         int n = s.nextInt();
         String str = s.next();
         boolean same = true;
         for(int i = 1; i < n; i++){
            if(str.charAt(i) != str.charAt(0)){
               same = false;
               break;
            }
         }
         if(same){
            System.out.println((n+2)/3);
            continue;
         }
         ArrayList<Integer> count = new ArrayList<Integer>();
         int last = 0;
         int cnt = 1;
         for(int i = 1; i < n; i++){
            if(str.charAt(i) == str.charAt(last)){
               cnt++;
            }else{
               count.add(cnt);
               last = i;
               cnt = 1;
            }
         }
         if(str.charAt(n-1) == str.charAt(0)){
            count.set(0, count.get(0)+cnt);
         }else{
            count.add(cnt);
         }
         int sum = 0;
         for(int i: count) sum+=(i/3);
         System.out.println(sum);
      }
   }

}


/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */

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

public class Main
{
   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;
      }

      int[] readArray(int n, int size){
         int[] a = new int[size];
         for(int i = 0; i < n; i++) {
            a[i] = this.nextInt();
         }

         return a;
      }

      long[] readLongArray(int n, int size){
         long[] a = new long[size];
         for(int i = 0; i < n; i++) {
            a[i] = this.nextLong();
         }
         return a;
      }
   }

   public static void main(String[] args) {
      FastReader s=new FastReader();
      int t = s.nextInt();

      for(int z = 0; z < t; z++) {

         int n = s.nextInt();
         String attack = s.next();
         long result = 0;
         char prev = attack.charAt(0);
         int prevCount = 0;
         for(int i = 1; i < attack.length(); i++){
            if(attack.charAt(i) == prev){
               prevCount++;
               if(prevCount == 3) {
                  result++;
                  prevCount = 1;
               }
            }
            else {
               prev = attack.charAt(i);
               prevCount = 1;
            }
         }
         if(n <= 3 || attack.charAt(n-1) != attack.charAt(0)) System.out.println(result);
         else {
            if(prevCount == 2) result++;
            else {
               if(attack.charAt(1) == prev) prevCount++;
               if(attack.charAt(2) == prev) prevCount++;
               if(prevCount == 3) result++;
            }
            System.out.println(result);
         }

      }
   }

}


/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */

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

public class Main
{
   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;
      }

      int[] readArray(int n, int size){
         int[] a = new int[size];
         for(int i = 0; i < n; i++) {
            a[i] = this.nextInt();
         }

         return a;
      }

      long[] readLongArray(int n, int size){
         long[] a = new long[size];
         for(int i = 0; i < n; i++) {
            a[i] = this.nextLong();
         }
         return a;
      }
   }

   public static void main(String[] args) {
      FastReader s=new FastReader();
      int t = s.nextInt();

      for(int z = 0; z < t; z++) {

         int n = s.nextInt();
         String attack = s.next();

         long result = 0;
         char prev = attack.charAt(0);
         int prevCount = 0;
         for(int i = 1; i < attack.length(); i++){
            if(attack.charAt(i) == prev){
               prevCount++;
               if(prevCount == 3) {
                  result++;
                  prevCount = 1;
               }
            }
            else {
               prev = attack.charAt(i);
               prevCount = 1;
            }
         }
         if(attack.charAt(n-1) != attack.charAt(0)) System.out.println(result);
         else {
            if(prevCount == 2) result++;
            System.out.println(result);
         }

      }
   }

}


/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */

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

public class Main
{
   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;
      }

      int[] readArray(int n, int size){
         int[] a = new int[size];
         for(int i = 0; i < n; i++) {
            a[i] = this.nextInt();
         }

         return a;
      }

      long[] readLongArray(int n, int size){
         long[] a = new long[size];
         for(int i = 0; i < n; i++) {
            a[i] = this.nextLong();
         }
         return a;
      }
   }

   public static void main(String[] args) {
      FastReader s=new FastReader();
      int t = s.nextInt();

      for(int z = 0; z < t; z++) {

         int n = s.nextInt();
         String attack = s.next();
         long result = 0;
         char prev = attack.charAt(0);
         int prevCount = 0;
         for(int i = 1; i < attack.length(); i++){
            if(attack.charAt(i) == prev){
               prevCount++;
               if(prevCount == 3) {
                  result++;
                  prevCount = 1;
               }
            }
            else {
               prev = attack.charAt(i);
               prevCount = 1;
            }
         }
         if(attack.charAt(n-1) != attack.charAt(0)) System.out.println(result);
         else {
            if(prevCount == 2) result++;
            else {
               if(attack.charAt(1) == prev) prevCount++;
               if(attack.charAt(2) == prev) prevCount++;
               if(prevCount == 3) result++;
            }
            System.out.println(result);
         }

      }
   }

}


import java.util.*;
import java.io.*;

public class QuestionD {
static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int t = sc.nextInt();
		while(t-->0) {
			solve();
		}
	}

	public static void solve() {
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int count = 0;
		for(int i = 0;i < n - 1;i++) {

			int prev = (i - 1 + n) % n;
			int next = (i + 1 + n ) % n;

			if(arr[prev] == arr[i] && arr[i] == arr[next]) {
				count++;
				arr[i] = arr[i] == 'R'? 'L' : 'R';
			}
		}

		System.out.println(count);
	}
}


import java.util.*;
import java.io.*;

public class QuestionD {
static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int t = sc.nextInt();
		while(t-->0) {
			solve();
		}
	}

	public static void solve() {
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int count = 0;
		for(int i = 0;i < n - 1;i++) {

			int prev = (i - 1 + n) % n;
			int next = (i + 1 + n ) % n;

			if(arr[prev] == arr[i] && arr[i] == arr[next]) {
				count++;
				i++;
			}
		}

		System.out.println(count);
	}
}


import java.util.*;
import java.io.*;

public class QuestionD {
static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int t = sc.nextInt();
		while(t-->0) {
			solve();
		}
	}

	public static void solve() {
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int count = 0;
		int start = 0;
		int i = 1;
		for(i = 1;i < n;i++) {
			if(arr[i] != arr[i - 1]) {
				start = i;
				break;
			}
		}

		if(i >= n) {
			double ans = (double)n/(double)3;
			System.out.println((int)Math.ceil(ans));
			return;
		}

		int sim = 1;
		int ans = 0;
		char ch = arr[start % n];
		for(i = 1;i < n;i++) {
			if(arr[(start + i) % n] == ch)sim++;
			else {
				ans += sim/3;
				sim = 1;
				ch = arr[(start + i) % n];
			}
		}

		ans += sim/3;
		System.out.println(ans);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;

public class Task4 {

    public static void main(String[] args) throws IOException {
        new Task4().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int t = Integer.parseInt(f.readLine());
        for (int t1 = 0; t1 < t; t1++) {
            int res = 0;
            int n = Integer.parseInt(f.readLine());
            char[] seq = f.readLine().toCharArray();
            boolean[] bad = new boolean[n];
            for (int i = 0; i < n; i++) {
                int goingIn = 0;
                if (seq[(i - 1 + n) % n] == 'R') goingIn++;
                if (seq[(i + 1 + n) % n] == 'L') goingIn++;
                if (goingIn == 1) {
                    if (seq[i] == 'L') {
                        if (seq[(i + 1 + n) % n] == 'L') {
                            //seq[i] = 'R';
                            bad[i] = true;
                        }
                    } else {
                        if (seq[(i - 1 + n) % n] == 'R') {
                            //seq[i] = 'L';
                            bad[i] = true;
                        }
                    }
                }
            }

            ArrayList<Integer> lengths = new ArrayList<Integer>();
            int a = 0;
            int firstLength = 0;
            while (a < n && bad[a]) {
                a++;
            }
            if (a == n) {
                firstLength = n;
                lengths.add(firstLength);
            } else {
                int b = n - 1;
                while (bad[b]) {
                    b--;
                }
                firstLength = a + n - 1 - b;
                lengths.add(firstLength);
                int currLength = 0;
                for (int i = a; i <= b; i++) {
                    if (bad[i]) currLength++;
                    else {
                        if (currLength != 0) {
                            lengths.add(currLength);
                            currLength = 0;
                        }
                    }
                }
                if (currLength != 0) lengths.add(currLength);
            }

            for (int length : lengths) {
                res += length / 3;
                if (length % 3 != 0) res++;
            }

            out.println(res);
        }

        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Task4 {

    public static void main(String[] args) throws IOException {
        new Task4().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int t = Integer.parseInt(f.readLine());
        for (int t1 = 0; t1 < t; t1++) {
            int res = 0;
            int n = Integer.parseInt(f.readLine());
            char[] seq = f.readLine().toCharArray();
            for (int i = 0; i < n; i++) {
                int goingIn = 0;
                if (seq[(i - 1 + n) % n] == 'R') goingIn++;
                if (seq[(i + 1 + n) % n] == 'L') goingIn++;
                if (goingIn == 1) {
                    if (seq[i] == 'L') {
                        if (seq[(i + 1 + n) % n] == 'L') {
                            seq[i] = 'R';
                            res++;
                        }
                    } else {
                        if (seq[(i - 1 + n) % n] == 'R') {
                            seq[i] = 'L';
                            res++;
                        }
                    }
                }
            }

            out.println(res);
        }

        out.close();
    }
}


 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,a[0])) return max;
             if (!check(back,a[0],a[1])) 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;
         }
     }

 }


 import java.util.*;

 public class Solution {
     static int rr,gg,bb;
     static Integer r[],g[],b[];

     public static void main(String[] args) {
         Scanner input = new Scanner(System.in);
         int t=input.nextInt();
         while (t-->0){
             int n=input.nextInt();
             char st[]=input.next().toCharArray();

             int ans=0;
             for (int i = 0; i <n ; i++) {
                 int k=0;
                 boolean left=false;
                 boolean right=false;
                 if (i!=0 && i!=n-1){
                     if (st[i-1]=='R'){
                         left=true;
                         k++;
                     }
                     if (st[i+1]=='L'){
                         right=true;
                         k++;
                     }

                 }
                 if (i==0){
                     if (st[n-1]=='R'){
                         left=true;
                         k++;
                     }
                     if (st[i+1]=='L'){
                         right=true;
                         k++;
                     }
                 }
                 if (i==n-1){
                     if (st[i-1]=='R'){
                         left=true;
                         k++;
                     }
                     if (st[0]=='L'){
                         right=true;
                         k++;
                     }
                 }

                 if (k==1){
                     if ((left && st[i]=='R')||(right && st[i]=='L')){
                         if (left) st[i]='L';
                         if (right) st[i]='R';
                         ans++;
                     }
                 }
             }
             System.out.println(ans);

         }

     }

 }