Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.

Chef has bought a new robot, which will be used for delivering dishes to his customers. He started testing the robot by letting it move on a line.

Initially, the robot is placed at the coordinate $x = X$. Then, it should execute a sequence of $N$ commands, described by a string $S$ with length $N$. Each character of this string is either 'L' or 'R', denoting that the robot should walk one step to the left (decreasing $x$ by $1$) or to the right (increasing $x$ by $1$), respectively.

How many distinct points are visited by the robot when it has executed all the commands? A point $p$ is visited by the robot if $p$ is an integer and the robot's position before or after executing some command is $x = p$.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $X$.
The second line contains a single string $S$ with length $N$.

------  Output ------
For each test case, print a single line containing one integer ― the number of points visited by the robot.

------  Constraints  ------
$1 ≤ T ≤ 100$
$1 ≤ N ≤ 100$
$|X| ≤ 1,000,000$
$S$ contains only characters 'L' and 'R'

------  Subtasks ------
Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
2

6 10

RRLLLL

2 0

LL
----- Sample Output 1 ------ 
5

3
----- explanation 1 ------ 
Example case 1: The robot followed the path $10 \rightarrow 11 \rightarrow 12 \rightarrow 11 \rightarrow 10 \rightarrow 9 \rightarrow 8$.

Example case 2: The robot followed the path $0 \rightarrow -1 \rightarrow -2$.

Difficulty: EASY
Tags: Data structures

Implementation
Skill types: Data structures

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	l = [x]
	for i in s:
		if i == 'R':
			x += 1
		else:
			x -= 1
		l.append(x)
	print(len(set(l)))


t = int(input())
for i in range(t):
	(len, n) = map(int, input().split())
	s = input()
	l = [n]
	count = 1
	for j in range(len):
		if s[j] == 'R':
			n = n + 1
		else:
			n = n - 1
		if n not in l:
			l.append(n)
			count = count + 1
	print(count)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = []
	l.append(x)
	s = input()
	for i in s:
		if i == 'R':
			x += 1
			if x not in l:
				l.append(x)
		elif i == 'L':
			x -= 1
			if x not in l:
				l.append(x)
	print(len(l))


test = int(input())
for i in range(test):
	(num, sta) = map(int, input().split())
	s = input()
	count = 0
	final = 0
	lis = [sta]
	lis2 = []
	for j in range(num):
		if s[j] == 'R':
			sta += 1
			lis.append(sta)
		else:
			sta -= 1
			lis2.append(sta)
	lis3 = lis + lis2
	list4 = [*set(lis3)]
	ex = list(list4)
	for k in ex:
		count += 1
	print(count)


t = int(input())
while t:
	(N, X) = map(int, input().split())
	S = input()
	arr = []
	arr.append(X)
	for i in S:
		if i == 'R':
			X += 1
			arr.append(X)
		if i == 'L':
			X -= 1
			arr.append(X)
	arr = set(arr)
	print(len(arr))
	t = t - 1


t = int(input())
for i in range(t):
	(n, x) = [int(a) for a in input().split()]
	s = input()
	l = []
	l.append(x)
	for i in s:
		if i == 'R':
			x = x + 1
			l.append(x)
		elif i == 'L':
			x = x - 1
			l.append(x)
	p = set(l)
	print(len(p))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	string = list(input())
	new = [x]
	for i in string:
		if i == 'R':
			new.append(new[-1] + 1)
		else:
			new.append(new[-1] - 1)
	print(len(set(new)))


for i in range(int(input())):
	(n, p) = map(int, input().split())
	s = list(input())
	t = [p]
	for i in s:
		if i == 'R':
			t.append(t[-1] + 1)
		else:
			t.append(t[-1] - 1)
	print(len(set(t)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	pos = [x]
	for m in s:
		if m == 'L':
			pos.append(x - 1)
			x -= 1
		else:
			pos.append(x + 1)
			x += 1
	print(len(set(pos)))


t = int(input())
while t > 0:
	(n, x) = [int(x) for x in input().split()]
	s = input()
	p = []
	p.append(x)
	for i in s:
		if i == 'L':
			x += 1
			p.append(x)
		if i == 'R':
			x -= 1
			p.append(x)
	set_p = set(p)
	print(len(set_p))
	t -= 1


t = int(input())

def steps():
	entry = input()
	e = entry.split()
	n = int(e[1])
	stops = n
	length = int(e[0])
	path = input()
	l = list(map(str, path))
	nstops = [n]
	for i in l:
		if i == 'R':
			stops += 1
			nstops.append(stops)
		if i == 'L':
			stops -= 1
			nstops.append(stops)
	dstop = len(set(nstops))
	return dstop
for i in range(t):
	print(steps())


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	ans = [x]
	for j in s:
		if j == 'L':
			x -= 1
			if x not in ans:
				ans.append(x)
		else:
			x += 1
			if x not in ans:
				ans.append(x)
	print(len(ans))


t = int(input())
for i in range(t):
	(l, p) = list(map(int, input().split()))
	s = input()
	ma = p
	mi = p
	for l in s:
		if l == 'R':
			p = p + 1
		else:
			p = p - 1
		mi = min(mi, p)
		ma = max(ma, p)
	print(ma - mi + 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	p = input()
	l = [x]
	for s in p:
		if s == 'R':
			x += 1
			l.append(x)
		if s == 'L':
			x -= 1
			l.append(x)
	print(len(set(l)))


for _ in range(int(input())):
	(n, p) = map(int, input().split())
	s = str(input())
	ans = [p]
	for i in s:
		if i == 'R':
			p += 1
			ans.append(p)
		elif i == 'L':
			p -= 1
			ans.append(p)
	print(len(set(ans)))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	k = []
	k.append(x)
	for i in range(n):
		if s[i] == 'R':
			x = x + 1
			k.append(x)
		elif s[i] == 'L':
			x = x - 1
			k.append(x)
	z = set(k)
	print(len(z))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	k = []
	c = 0
	k.append(x)
	for i in s:
		if i == 'R':
			x = x + 1
		else:
			x = x - 1
		if x not in k:
			k.append(x)
	print(len(k))


t = int(input())
for i in range(t):
	(N, X) = list(map(int, input().split()))
	string = list(input())
	new = [X]
	for j in string:
		if j == 'R':
			new.append(new[-1] + 1)
		else:
			new.append(new[-1] - 1)
	print(len(set(new)))


T = int(input())
for k in range(T):
	arr1 = []
	(a, b) = map(int, input().split())
	arr = list(map(str, input().strip()))
	arr1.append(b)
	for item in arr:
		if item == 'R':
			b += 1
			arr1.append(b)
		else:
			b -= 1
			arr1.append(b)
	print(len(set(arr1)))


s = int(input())
for i in range(s):
	(a, b) = map(int, input().split(' '))
	n = input()
	lst = set()
	lst.add(b)
	for j in range(a):
		if n[j] == 'R':
			b = b + 1
			lst.add(b)
		if n[j] == 'L':
			b = b - 1
			lst.add(b)
	print(len(lst))


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	s = input()
	pos = [x]
	for k in s:
		if k == 'R':
			pos.append(x + 1)
			x += 1
		else:
			pos.append(x - 1)
			x -= 1
	print(len(set(pos)))


N = int(input())
for i in range(N):
	(S, N) = map(int, input().split())
	s1 = input()
	l1 = []
	l1.append(N)
	for j in s1:
		if j == 'R':
			N += 1
			l1.append(N)
		elif j == 'L':
			N -= 1
			l1.append(N)
		else:
			pass
	l2 = list(set(l1))
	print(len(l2))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s = input()
	l = [b]
	for i in s:
		if i == 'L':
			b += 1
		else:
			b -= 1
		l.append(b)
	s = set(l)
	print(len(s))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	lf = [x]
	for i in s:
		if i == 'R':
			lf.append(lf[-1] + 1)
		else:
			lf.append(lf[-1] - 1)
	print(len(set(lf)))


t = int(input())
for i in range(t):
	(n, x) = map(eval, input().split())
	s = input()
	o = x
	a = 0
	h = [o]
	k = [j for j in s]
	for i in range(n):
		if k[i] == 'L':
			x = x - 1
			if x not in h:
				a += 1
		else:
			x = x + 1
			if x not in h:
				a += 1
		h.append(x)
	print(a + 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	t = list((s[j] for j in range(n)))
	co = [x]
	for i in range(n):
		if s[i] == 'R':
			x += 1
		else:
			x -= 1
		co.append(x)
	p = set(co)
	print(len(p))


for _ in range(int(input())):
	(s, n) = map(int, input().split(' '))
	c = input()
	l = []
	l.append(n)
	for i in c:
		if i == 'R':
			n += 1
			if n not in l:
				l.append(n)
		else:
			n -= 1
			if n not in l:
				l.append(n)
	print(len(l))


t = int(input())
l = []
for i in range(t):
	(N, X) = map(int, input().split())
	x = X
	l.append(x)
	S = input()
	count = 1
	for j in S:
		if j == 'L':
			x -= 1
			if x not in l:
				count += 1
		elif j == 'R':
			x += 1
			if x not in l:
				count += 1
		l.append(x)
	print(count)


for i in range(int(input())):
	t = list(map(int, input().split()))
	(n, x) = (t[0], t[1])
	s = input()
	s1 = set()
	s1.add(x)
	for i in s:
		if i == 'R':
			x += 1
			s1.add(x)
		elif i == 'L':
			x -= 1
			s1.add(x)
	print(len(s1))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d, e) = (input(), [b], 1)
	for i in c:
		if i == 'R':
			b += 1
			if b not in d:
				d.append(b)
				e += 1
		else:
			b -= 1
			if b not in d:
				d.append(b)
				e += 1
	print(e)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	s1 = {x}
	for i in s:
		if i == 'L':
			x = x + 1
		else:
			x = x - 1
		s1.add(x)
	print(len(s1))


for _ in range(int(input())):
	(n, x) = map(int, input().split(' '))
	s = input()
	arr = []
	arr.append(x)
	for i in s:
		if i == 'R':
			x += 1
		else:
			x -= 1
		if x not in arr:
			arr.append(x)
	print(len(arr))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	pos = [x]
	for i in s:
		if i == 'L':
			pos.append(x - 1)
			x = x - 1
		else:
			pos.append(x + 1)
			x = x + 1
	print(len(set(pos)))


for _ in range(int(input())):
	(p, u) = map(int, input().split())
	w = set()
	o = input()
	w.add(u)
	for r in o:
		if r == 'R':
			u += 1
		else:
			u -= 1
		w.add(u)
	print(len(w))
	w.clear()


for dvav in range(int(input())):
	(n, x) = map(int, input().split())
	a = input()
	temp = []
	temp.append(x)
	for i in range(len(a)):
		if a[i] == 'R':
			x += 1
			temp.append(x)
		elif a[i] == 'L':
			x -= 1
			temp.append(x)
	temp = set(temp)
	print(len(temp))


n = int(input())
for i in range(n):
	(n1, n2) = list(map(int, input().split()))
	s = input()
	s1 = [n2]
	for i in s:
		if i == 'L':
			n2 -= 1
		elif i == 'R':
			n2 += 1
		if n2 not in s1:
			s1.append(n2)
	print(len(s1))


for _ in range(int(input())):
	(n, x) = map(int, input().split(' '))
	s = input()
	a = [x]
	for i in s:
		if i == 'L':
			x -= 1
		else:
			x += 1
		if x not in a:
			a.append(x)
	print(len(a))


for _ in range(int(input())):
	(n, l) = map(int, input().split())
	s = list(input().lower())
	l1 = [l]
	for i in range(n):
		if s[i] == 'l':
			v = -1
		else:
			v = +1
		l = l + v
		l1.append(l)
	print(len(set(l1)))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = list(input())
	res = []
	res.append(x)
	for j in range(n):
		if s[j] == 'R':
			x = x + 1
			if x not in res:
				res.append(x)
		else:
			x = x - 1
			if x not in res:
				res.append(x)
	print(len(res))


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	s = input()
	l = set()
	l.add(n)
	for i in s:
		if i == 'L':
			n = n - 1
			l.add(n)
		if i == 'R':
			n = n + 1
			l.add(n)
	print(len(l))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	s = str(input())
	p = set([x])
	for i in range(n):
		if s[i] == 'R':
			x = x + 1
		else:
			x = x - 1
		p.add(x)
	print(len(p))


for i in range(int(input())):
	(N, X) = map(int, input().split())
	s = input()
	v = X
	k = []
	k.append(X)
	for m in s:
		if m == 'R':
			v = v + 1
			k.append(v)
		if m == 'L':
			v = v - 1
			k.append(v)
	o = set(k)
	print(len(o))


TC = int(input())
for T in range(TC):
	(N, X) = map(int, input().split())
	S = input()
	p = set([X])
	for c in S:
		if c == 'L':
			X -= 1
		else:
			X += 1
		p.add(X)
	print(len(p))


def fun(s, x):
	l = []
	count = 1
	l.append(x)
	for i in s:
		if i == 'R':
			x = x + 1
		else:
			x = x - 1
		if l.count(x) == 0:
			l.append(x)
			count += 1
	return count
t = int(input())
for i in range(0, t):
	(n, x) = map(int, input().split())
	s = input()
	print(fun(s, x))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(input())
	a = [x]
	for i in s:
		if i == 'R':
			a.append(a[-1] + 1)
		else:
			a.append(a[-1] - 1)
	print(len(set(a)))


from collections import Counter

def test():
	(n, x) = map(int, input().split())
	s = input()
	cnt = 1
	res = []
	res.append(x)
	for i in s:
		if i == 'R':
			x += 1
			if x not in res:
				res.append(x)
		else:
			x -= 1
			if x not in res:
				res.append(x)
	print(len(res))
t = int(input())
for _ in range(t):
	test()


for i in range(int(input())):
	x = list(map(int, input().split()))
	v = input()
	c = x[1]
	l = []
	l.append(c)
	for i in v:
		if i == 'R':
			c = c + 1
		elif i == 'L':
			c = c - 1
		if c not in l:
			l.append(c)
	print(len(l))


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	s = list(input())
	j = [x]
	for i in range(len(s)):
		if s[i] == 'R':
			x = x + 1
			j.append(x)
		else:
			x = x - 1
			j.append(x)
	print(len(set(j)))
	t = t - 1


T = int(input())
for i in range(0, T):
	final = []
	f = input()
	x = f.split(' ')
	N = int(x[0])
	X = int(x[1])
	final.append(X)
	string = input()[:N]
	for j in range(0, N):
		if string[j] == 'R':
			X = X + 1
			final.append(X)
		if string[j] == 'L':
			X = X - 1
			final.append(X)
	print(len(set(final)))


n = int(input())
for i in range(n):
	(T, H) = input().split()
	t = int(T)
	h = int(H)
	L = [h]
	s = input()[:t]
	for j in s:
		if j == 'L':
			h = h - 1
		else:
			h = h + 1
		L.append(h)
	s = set(L)
	print(len(s))


import math
for t in range(int(input())):
	(x, y) = map(int, input().split())
	st = input()
	l = [y]
	for i in st:
		if i == 'L':
			y += 1
		else:
			y -= 1
		l.append(y)
	s = set(l)
	print(len(s))


t = int(input())
for i in range(t):
	(n, c) = map(int, input().split())
	a = input()
	d = {}
	for i in a:
		if c not in d:
			d[c] = 1
		else:
			d[c] += 1
		if i == 'R':
			c += 1
		else:
			c -= 1
	if c not in d:
		d[c] = 1
	else:
		d[c] += 1
	print(len(d))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	s = input()
	temp = [y]
	for i in s:
		if i == 'R':
			if y + 1 not in temp:
				temp.append(y + 1)
			y = y + 1
		else:
			if y - 1 not in temp:
				temp.append(y - 1)
			y = y - 1
	print(len(temp))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	s = list(input())
	l = [b]
	for i in range(len(s)):
		if s[i] == 'R':
			l.append(l[len(l) - 1] + 1)
		else:
			l.append(l[len(l) - 1] - 1)
	print(len(set(l)))


t = int(input())
for i in range(0, t):
	(n, x) = map(int, input().split())
	s = list(input())
	l = []
	L = [x]
	for j in s:
		if j == 'R':
			x = x + 1
			l.append(x)
		if j == 'L':
			x = x - 1
			l.append(x)
	l = l + L
	l = set(l)
	print(len(l))