// Arup Guha
// 5/6/2022
// Solution to UCF HS Online Contest Problem: Snow Day

import java.util.*;

public class snowy {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=0; loop<nC; loop++) {
		
			// Read snowmen heights.
			int n = stdin.nextInt();
			int[] values = new int[n];
			item[] list = new item[n];
			for (int i=0; i<n; i++) {
				int h = stdin.nextInt();
				list[i] = new item(h, i);
			}
			
			// Sort objects.
			Arrays.sort(list);
			
			// Get directions.
			char[] dir = stdin.next().toCharArray();
			
			// indexes of snowmen who are standing.
			TreeSet<Integer> ts = new TreeSet<Integer>();
			for (int i=0; i<n; i++) ts.add(i);
			
			// # of turns.
			int res = 0;
			
			// index in sorted list of snowman to be pushed.
			int idx = 0;
			
			while (ts.size() > 0) {
			
				// Snowman to be pushed down next.
				int curS = list[idx].index;
				
				// This one already died :(
				if (!ts.contains(curS)) {
					idx++;
					continue;
				}
				
				// Push the snowman.
				push(curS, list[idx].value, ts, dir[res] == 'R'); 
				res++;
			}
			
			// Ta da!
			System.out.println(res);
		}
	}
	
	public static void push(int sI, int numKill, TreeSet<Integer> ts, boolean right) {
	
		// Don't need to simulate just empty out the TreeSet.
		if (ts.size() <= numKill) {
			ts.clear();
			return;
		}
		
		// The current snowman is dead.
		ts.remove(sI);
		numKill--;
		
		// Last Killed.
		int cur = sI;
		
		// Just remove the rest.
		for (int i=0; i<numKill; i++) {
		
			Integer tmp = null;
			
			// Going right.
			if (right) {
			
				// Get next circular to the right.
				tmp = ts.higher(cur);
				if (tmp == null) tmp = ts.first();				
			}
			
			// Going left.
			else {
				tmp = ts.lower(cur);
				if (tmp == null) tmp = ts.last();
			}
			
			// Remove and update tmp.
			ts.remove(tmp);
			cur = tmp;			
		}
	}
}

class item implements Comparable<item> {

	public int value;
	public int index;
	
	public item(int v, int i) {
		value = v;
		index = i;
	}
	
	public int compareTo(item other) {
		if (this.value != other.value)
			return other.value - this.value;
		return this.index - other.index;
	}
}