import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = readln.strip.map !(q{a == 'R'}).array;
		auto t = s ~ s ~ s;
		immutable int [] toFind = [0, 1];
		auto pos = t.countUntil (toFind).to !(int);
		if (pos == -1)
		{
			writeln ((n + 2) / 3);
			continue;
		}

		pos += 1;
		writeln (t[pos..pos + n].group.map !(q{(a[1] + 0) / 3}).sum);
	}
}
