// Andrew Miller
// Solution to 2006 BHCSI Contest Problem Snake
import java.util.*;
import java.io.*;

/* This little class makes it easier to use Java Collections to model the snake */
class Coord
{
	public int x;
	public int y;

	public Coord(int x, int y)
	{
		this.x = x;
		this.y = y;
	}

	public boolean equals(Object o)
	{
		Coord c = (Coord) o;
		return c.x == x && c.y == y;
	}

	public String toString()
	{
		return "(" + x + "," + y + ")";
	}
}

public class snake
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(new File("snake.in"));

		int n = sc.nextInt();

		while (n > 0)
		{
			/* The snake always starts in the top left corner */
			LinkedList<Coord> snake = new LinkedList<Coord>();
			snake.add(new Coord(0, 0));

			/* This array holds the possible direction vectors, in clockwise order */
			Coord[] d =
			{
				new Coord(0, 1),
				new Coord(-1, 0),
				new Coord(0, -1),
				new Coord(1, 0),
			};

			/* Start by going down */ 
			int dir = 0;

			/* How many iterations has the snake survived? */
			int counter = 1;

			while (n > 0)
			{
				String s = sc.next();
				n--;

				/* Do a left hand or right hand turn */
				if (s.equals("L"))
					dir = (dir + 3) % 4;
				if (s.equals("R"))
					dir = (dir + 1) % 4;

				/* The new 'head' will be one space away from the current one */
				Coord head = snake.getFirst();				
				Coord next = new Coord(head.x + d[dir].x, head.y + d[dir].y);

				/* If the snake has reached its full size, remove the tail */
				if (snake.size() == 10)
					snake.removeLast();

				/* If it hits a wall (goes out of bounds) or runs into itself, quit */
				if (!inBounds(next) || snake.contains(next))
				{
					System.out.println(counter);
					break;
				}

				/* Add the new head */
				snake.addFirst(next);

				counter++;
			}
		}

	}

	public static boolean inBounds(Coord test)
	{
		return test.x >= 0 && test.y >= 0 && test.x < 10 && test.y < 10;
	}
}