So, your output is wrong.
You print the output in tuple formation which is wrong. If you use tuple function for your output, it would be in this ‘()’ bracket, like your output (0,1) which is wrong. Your output for this above input should be:
0 1
-2 1
-1 -1
I think it will help to understand where are you wrong.
Here is my program:
t = int(input())
for i in range(t):
n = int(input())
s = input()
li1 = list(s)
k = 1
a,b=0,0
if li1[0] == 'L':
a -= 1
elif li1[0] == 'R':
a += 1
elif li1[0] == 'U':
b += 1
elif li1[0] == 'D':
b -= 1
for i in range(len(li1)-1):
if (li1[k] == 'L' and li1[k-1] != 'L' and li1[k-1] != 'R'):
a -= 1
elif (li1[k] == 'R' and li1[k-1] != 'L' and li1[k-1] != 'R'):
a += 1
elif (li1[k] == 'U' and li1[k-1] != 'U' and li1[k-1] != 'D'):
b += 1
elif (li1[k] == 'D' and li1[k-1] != 'U' and li1[k-1] != 'D'):
b -= 1
k = k + 1
print(a,b)
you have to print the output after each test case , as if after any test case online judge didn’t get the desired output or no output then it will give WA verdict.
for _ in range(int(input())):
n = int(input()); s = input()
if s[0]=='L':
x = -1; y = 0
elif s[0]=='R':
x = 1; y = 0
elif s[0]=='U':
x = 0; y = 1
else:
x = 0; y = -1
for i in range(1,n):
if s[i]==s[i-1]:
continue
elif s[i]=='L':
if s[i-1]!='R':
x -= 1
elif s[i]=='R':
if s[i-1] != 'L':
x += 1
elif s[i]=='U':
if s[i-1]!='D':
y += 1
elif s[i]=='D':
if s[i-1]!='U':
y -= 1
print(x,y)