#include "casino.h"
#include <iostream>

namespace Lgrader{
	int n;
	std::vector<std::vector<int>> Chiaro(std::vector<std::vector<int>> T, const std::string& moves){
		for(int i = 0, x = 0, y = 0; i < moves.size(); i ++){
			T[x][y] ^= 1;
			if(moves[i] == 'R') ++ y;
			else				++ x;
		}
		T[n - 1][n - 1] ^= 1;
		return T;
	}
};

void play_game(){
	int length; std::cin >> length;
	std::string str; std::cin >> str;
	std::string moves; std::cin >> moves;
	auto T = Azzurro(Lgrader::n, length, str);
	T = Lgrader::Chiaro(T, moves);
	std::cout << Bordeaux(Lgrader::n, length, T) << std::endl;
}

int main(){
	int games; cin >> games >> Lgrader::n;
	for(int i = 0; i < games; i ++){
		play_game();
	}
}
