There are $n$ robots driving along an OX axis. There are also two walls: one is at coordinate $0$ and one is at coordinate $m$.

The $i$-th robot starts at an integer coordinate $x_i~(0 < x_i < m)$ and moves either left (towards the $0$) or right with the speed of $1$ unit per second. No two robots start at the same coordinate.

Whenever a robot reaches a wall, it turns around instantly and continues his ride in the opposite direction with the same speed.

Whenever several robots meet at the same integer coordinate, they collide and explode into dust. Once a robot has exploded, it doesn't collide with any other robot. Note that if several robots meet at a non-integer coordinate, nothing happens.

For each robot find out if it ever explodes and print the time of explosion if it happens and $-1$ otherwise.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.

Then the descriptions of $t$ testcases follow.

The first line of each testcase contains two integers $n$ and $m$ ($1 \le n \le 3 \cdot 10^5$; $2 \le m \le 10^8$) — the number of robots and the coordinate of the right wall.

The second line of each testcase contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 < x_i < m$) — the starting coordinates of the robots.

The third line of each testcase contains $n$ space-separated characters 'L' or 'R' — the starting directions of the robots ('L' stands for left and 'R' stands for right).

All coordinates $x_i$ in the testcase are distinct.

The sum of $n$ over all testcases doesn't exceed $3 \cdot 10^5$.


-----Output-----

For each testcase print $n$ integers — for the $i$-th robot output the time it explodes at if it does and $-1$ otherwise.


-----Examples-----

Input
5
7 12
1 2 3 4 9 10 11
R R L L R R R
2 10
1 6
R R
2 10
1 3
L L
1 10
5
R
7 8
6 1 7 2 3 5 4
R L R L L L L
Output
1 1 1 1 2 -1 2 
-1 -1 
2 2 
-1 
-1 2 7 3 2 7 3


-----Note-----

Here is the picture for the seconds $0, 1, 2$ and $3$ of the first testcase:

Notice that robots $2$ and $3$ don't collide because they meet at the same point $2.5$, which is not integer.

After second $3$ robot $6$ just drive infinitely because there's no robot to collide with.

Source: codeforces | Difficulty: HARD
Tags: Sorting

Data structures

Implementation

Greedy algorithms


Solutions:
import sys
import getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
(yes, no) = ('YES', 'NO')
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def minus_one(arr):
	return [x - 1 for x in arr]

def minus_one_matrix(mrr):
	return [[x - 1 for x in row] for row in mrr]

def solve_(lst, dir, n, m):
	zrr = [(pos, d, i) for (i, (pos, d)) in enumerate(zip(lst, dir))]
	del lst
	del dir
	zrr.sort()
	res = [-1] * len(zrr)

	def proc(val):
		stack2 = deque([])
		for (p, d, i) in zrr:
			if p & 1 == val:
				continue
			if d == -1 and stack2 and (stack2[-1][1] == 1):
				(p2, d2, i2) = stack2.pop()
				t = abs(p2 - p) >> 1
				res[i] = t
				res[i2] = t
			else:
				stack2.append((p, d, i))
		while len(stack2) >= 2:
			(p, d, i) = stack2.popleft()
			(p2, d2, i2) = stack2.popleft()
			if not d == d2 == -1:
				stack2.appendleft((p2, d2, i2))
				stack2.appendleft((p, d, i))
				break
			t = p2 + p >> 1
			res[i] = t
			res[i2] = t
		while len(stack2) >= 2:
			(p, d, i) = stack2.pop()
			(p2, d2, i2) = stack2.pop()
			if not d == d2 == 1:
				stack2.append((p2, d2, i2))
				stack2.append((p, d, i))
				break
			t = m - p2 + m - p >> 1
			res[i] = t
			res[i2] = t
		assert len(stack2) <= 2
		if len(stack2) == 2:
			assert stack2[0][1] == -1 and stack2[1][1] == 1
			(p, d, i) = stack2.popleft()
			(p2, d2, i2) = stack2.pop()
			t = m + (m - p2) + p >> 1
			res[i] = t
			res[i2] = t
	proc(1)
	proc(0)
	return res
for case_num in range(int(input())):
	(n, m) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	dir = input().split()
	dir = [1 if val == 'R' else -1 for val in dir]
	res = solve(lst, dir, n, m)
	res = ' '.join((str(x) for x in res))
	print(res)


from operator import itemgetter
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve(n, m, x, s):
	arr = sorted([(i, x[i], s[i]) for i in range(n)], key=itemgetter(1))
	stacks = [[], []]
	ans = [-1] * n
	for (i, xi, si) in arr:
		stk = stacks[xi % 2]
		if not stk:
			stk.append((i, xi, si))
		else:
			(oi, ox, os) = stk[-1]
			if os == 'R' and si == 'L':
				ans[i] = ans[oi] = (xi - ox) // 2
				stk.pop()
			elif os == 'L' and si == 'L':
				ans[i] = ans[oi] = (xi + ox) // 2
				stk.pop()
			else:
				stk.append((i, xi, si))
	for stk in stacks:
		stk.reverse()
		l = len(stk)
		for i in range(0, l, 2):
			if i >= l - 2:
				break
			(ii, xi, _) = stk[i]
			(oi, ox, _) = stk[i + 1]
			ans[ii] = ans[oi] = (2 * m - ox - xi) // 2
		if i == l - 2:
			(ii, xi, si) = stk[i]
			(oi, ox, os) = stk[i + 1]
			if si == 'R' and os == 'R':
				ans[ii] = ans[oi] = (2 * m - ox - xi) // 2
			elif si == 'R' and os == 'L':
				ans[ii] = ans[oi] = (2 * m - xi + ox) // 2
	print(*ans)
T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	s = input().split()
	solve(n, m, x, s)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7

def first(a, b):
	r = []
	for i in range(len(a)):
		if b[i] == 'R':
			r += (a[i],)
		elif r:
			x = abs(r[-1] - a[i]) // 2
			ans[ind[a[i]]] = x
			ans[ind[r.pop()]] = x
	for i in range(len(a)):
		if ans[ind[a[i]]] != -1:
			a[i] = 0

def sec():
	global a, b
	b = [b[i] for i in range(len(a)) if a[i]]
	a = [i for i in a if i]
	l = []
	r = []
	for i in range(len(a)):
		if b[i] == 'L':
			l += (a[i],)
		else:
			r += (a[i],)
	l.reverse()
	for i in range(len(l) // 2):
		x = abs(l[-1] - l[-2]) // 2 + l[-1]
		ans[ind[l.pop()]] = x
		ans[ind[l.pop()]] = x
	for i in range(len(r) // 2):
		x = abs(r[-1] - r[-2]) // 2 + m - r[-1]
		ans[ind[r.pop()]] = x
		ans[ind[r.pop()]] = x
	if l and r:
		x = abs(r[-1] - l[-1]) // 2 + m - r[-1] + l[-1]
		ans[ind[r.pop()]] = x
		ans[ind[l.pop()]] = x
for _ in range(I()):
	(n, m) = R()
	a = L()
	ind = {}
	for i in range(n):
		ind[a[i]] = i
	dr = S().split()
	p = sorted(zip(a, dr))
	a = [i[0] for i in p]
	dr = [i[1] for i in p]
	e = []
	de = []
	o = []
	do = []
	for i in range(n):
		if a[i] % 2:
			o += (a[i],)
			do += (dr[i],)
		else:
			e += (a[i],)
			de += (dr[i],)
	ans = [-1] * n
	first(e, de)
	first(o, do)
	a = e
	b = de
	sec()
	a = o
	b = do
	sec()
	print(*ans)


import sys
from sys import stdout
input = lambda : sys.stdin.readline().rstrip('\r\n')
P = lambda : list(map(int, input().split()))
from math import factorial as f
from collections import deque, Counter as C
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge
mod = 10 ** 9 + 7
a = ord('A')
tc = int(input())
for _ in range(tc):
	(n, m) = P()
	lo = P()
	d = input().split()
	odd = []
	even = []
	for (a, b) in zip(lo, d):
		if a % 2:
			odd.append((a, b))
		else:
			even.append((a, b))
	dist = {}
	odd.sort()
	even.sort()
	ls = [odd, even]
	for lll in ls:
		l = []
		r = []
		for (a, b) in lll:
			if b == 'R':
				r.append(a)
			elif r:
				x = r.pop()
				dist[x] = dist[a] = (a - x) // 2
			else:
				l.append(a)
		for i in range(len(r) // 2):
			(a, b) = (r.pop(), r.pop())
			dist[a] = dist[b] = m - b + (b - a) // 2
		l = l[::-1]
		for i in range(len(l) // 2):
			(a, b) = (l.pop(), l.pop())
			dist[a] = dist[b] = a + (b - a) // 2
		while l and r:
			(a, b) = (l.pop(), r.pop())
			x = max(a, m - b)
			a1 = abs(a - x)
			b1 = b + x
			if b1 > m:
				b1 = m - (b1 - m)
			dist[a] = dist[b] = x + (b1 - a1) // 2
	for i in lo:
		print(dist.get(i, -1), end=' ')
	print()


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True

def solve(arr, n, m, ansl):
	pre = []
	for i in arr:
		if i[1] == 'R':
			pre.append(i)
		elif len(pre) == 0:
			pre.append((-i[0], 'R', i[2]))
		else:
			x = (i[0] - pre[-1][0]) // 2
			ansl[i[2]] = x
			ansl[pre[-1][2]] = x
			pre.pop()
	while len(pre) > 1:
		a = pre.pop()
		b = pre.pop()
		x = m - (a[0] + b[0]) // 2
		ansl[a[2]] = x
		ansl[b[2]] = x
	return ansl
for _ in range(int(inp())):
	(n, m) = mp()
	arr = lmp()
	s = list(inp().split())
	ansl = l1d(n, -1)
	odd = [(arr[i], s[i], i) for i in range(n) if arr[i] % 2]
	even = [(arr[i], s[i], i) for i in range(n) if arr[i] % 2 == 0]
	odd.sort()
	even.sort()
	ansl = solve(odd, len(odd), m, ansl)
	ansl = solve(even, len(even), m, ansl)
	outa(*ansl)


from sys import stdin, stdout
import heapq
from collections import defaultdict
import math
import bisect
import io, os
ans = []

def do(arr, m):
	global ans
	arr.sort()
	stack = []
	for (x, d, pos) in arr:
		if not stack:
			stack.append((x, d, pos))
			continue
		if d == 'L' and stack[-1][1] == 'R':
			ans[pos] = (x - stack[-1][0]) // 2
			ans[stack[-1][2]] = (x - stack[-1][0]) // 2
			stack.pop()
			continue
		stack.append((x, d, pos))
	if not stack:
		return
	pos_l = 0
	while pos_l < len(stack) and stack[pos_l][1] == 'L':
		pos_l += 1
	L = stack[:pos_l]
	R = stack[pos_l:]
	L.reverse()
	while L:
		if len(L) == 1:
			break
		(l1, _, pos1) = L.pop()
		(l2, _, pos2) = L.pop()
		ans[pos1] = (l2 - l1) // 2 + l1
		ans[pos2] = (l2 - l1) // 2 + l1
	while R:
		if len(R) == 1:
			break
		(r1, _, pos1) = R.pop()
		(r2, _, pos2) = R.pop()
		ans[pos1] = (r1 - r2) // 2 + (m - r1)
		ans[pos2] = (r1 - r2) // 2 + (m - r1)
	if L and R:
		(l, _, pos_l) = L[0]
		(r, _, pos_r) = R[0]
		ans[pos_l] = (2 * m + l - r) // 2
		ans[pos_r] = (2 * m + l - r) // 2

def main():
	global ans
	t = int(stdin.readline())
	for _ in range(t):
		(n, m) = list(map(int, stdin.readline().split()))
		arr = list(map(int, stdin.readline().split()))
		direc = list(map(str, stdin.readline().split()))
		ans = [-1] * n
		even = []
		odd = []
		for i in range(n):
			if arr[i] % 2 == 0:
				even.append((arr[i], direc[i], i))
			else:
				odd.append((arr[i], direc[i], i))
		do(even, m)
		do(odd, m)
		stdout.write(' '.join([str(x) for x in ans]) + '\n')
main()


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(n, m) = map(int, stdin.readline().split())
	xtmp = list(map(int, stdin.readline().split()))
	stmp = list(stdin.readline().split())
	xs = [(xtmp[i], stmp[i], i) for i in range(n)]
	xs.sort()
	x = [xs[i][0] for i in range(n)]
	s = [xs[i][1] for i in range(n)]
	ind = [xs[i][2] for i in range(n)]
	ans = [-1] * n
	ostk = []
	estk = []
	for i in range(n):
		if x[i] % 2 == 1:
			if s[i] == 'R':
				estk.append((x[i], s[i], ind[i]))
			elif len(estk) > 0 and estk[-1][1] == 'R':
				(lx, ls, li) = estk[-1]
				del estk[-1]
				(rx, rs, ri) = (x[i], s[i], ind[i])
				ans[li] = ans[ri] = abs(rx - lx) // 2
			else:
				estk.append((x[i], s[i], ind[i]))
		elif s[i] == 'R':
			ostk.append((x[i], s[i], ind[i]))
		elif len(ostk) > 0 and ostk[-1][1] == 'R':
			(lx, ls, li) = ostk[-1]
			del ostk[-1]
			(rx, rs, ri) = (x[i], s[i], ind[i])
			ans[li] = ans[ri] = abs(rx - lx) // 2
		else:
			ostk.append((x[i], s[i], ind[i]))
	OL = []
	OR = []
	for i in ostk:
		if i[1] == 'L':
			OL.append(i)
		else:
			OR.append(i)
	OL.reverse()
	while len(OL) >= 2:
		(lx, ls, li) = OL[-1]
		del OL[-1]
		(rx, rs, ri) = OL[-1]
		del OL[-1]
		ans[li] = ans[ri] = (lx + rx) // 2
	while len(OR) >= 2:
		(lx, ls, li) = OR[-1]
		del OR[-1]
		(rx, rs, ri) = OR[-1]
		del OR[-1]
		ans[li] = ans[ri] = (m - lx + (m - rx)) // 2
	EL = []
	ER = []
	for i in estk:
		if i[1] == 'L':
			EL.append(i)
		else:
			ER.append(i)
	EL.reverse()
	while len(EL) >= 2:
		(lx, ls, li) = EL[-1]
		del EL[-1]
		(rx, rs, ri) = EL[-1]
		del EL[-1]
		ans[li] = ans[ri] = (lx + rx) // 2
	while len(ER) >= 2:
		(lx, ls, li) = ER[-1]
		del ER[-1]
		(rx, rs, ri) = ER[-1]
		del ER[-1]
		ans[li] = ans[ri] = (m - lx + (m - rx)) // 2
	if True:
		if len(OL) > 0 and len(OR) > 0:
			(lx, ls, li) = OL[0]
			(rx, rs, ri) = OR[0]
			ans[li] = ans[ri] = (lx + m + (m - rx)) // 2
		if len(EL) > 0 and len(ER) > 0:
			(lx, ls, li) = EL[0]
			(rx, rs, ri) = ER[0]
			ans[li] = ans[ri] = (lx + m + (m - rx)) // 2
	print(*ans)


import os
import sys
from collections import Counter
from io import BytesIO, IOBase
from math import gcd, inf, sqrt, ceil
sys.setrecursionlimit(2 * 10 ** 5)

def lcm(a, b):
	return a * b // gcd(a, b)

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = set()
	while x != 1:
		ret.add(spf[x])
		x = x // spf[x]
	return ret

def printDivisors(n):
	i = 2
	z = [1, n]
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				z.append(i)
			else:
				z.append(i)
				z.append(n // i)
		i = i + 1
	return z

def create(n, x, f):
	pq = len(bin(n)[2:])
	if f == 0:
		tt = min
	else:
		tt = max
	dp = [[inf] * n for _ in range(pq)]
	dp[0] = x
	for i in range(1, pq):
		for j in range(n - (1 << i) + 1):
			dp[i][j] = tt(dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
	return dp

def enquiry(l, r, dp, f):
	if l > r:
		return inf if not f else -inf
	if f == 1:
		tt = max
	else:
		tt = min
	pq1 = len(bin(r - l + 1)[2:]) - 1
	return tt(dp[pq1][l], dp[pq1][r - (1 << pq1) + 1])

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	x = []
	for i in range(2, n + 1):
		if prime[i]:
			x.append(i)
	return x

def func(xx, an, o, m):
	st = []
	for i in range(len(xx)):
		if not st or st[-1][1] == xx[i][1]:
			st.append(xx[i])
		elif st[-1][1] == 'L':
			st.append(xx[i])
		else:
			tmp = st[-1]
			an[o[tmp[0]]] = abs(xx[i][0] - tmp[0]) // 2
			an[o[xx[i][0]]] = abs(xx[i][0] - tmp[0]) // 2
			st.pop()
	c = -1
	for i in range(0, len(st), 2):
		if i != len(st) - 1:
			if st[i][1] == 'R' or st[i + 1][1] == 'R':
				break
			else:
				an[o[st[i][0]]] = abs(st[i][0] - st[i + 1][0]) // 2 + min(st[i][0], st[i + 1][0])
				an[o[st[i + 1][0]]] = abs(st[i][0] - st[i + 1][0]) // 2 + min(st[i][0], st[i + 1][0])
				c = i + 1
	cc = len(st)
	for i in range(len(st) - 1, -1, -2):
		if i != 0:
			if st[i][1] == 'L' or st[i - 1][1] == 'L':
				break
			else:
				an[o[st[i][0]]] = abs(st[i][0] - st[i - 1][0]) // 2 + m - max(st[i][0], st[i - 1][0])
				an[o[st[i - 1][0]]] = abs(st[i][0] - st[i - 1][0]) // 2 + m - max(st[i][0], st[i - 1][0])
				cc = i - 1
	if cc - c - 1 == 2:
		tmp1 = min(st[c + 1][0], st[cc - 1][0])
		tmp2 = m - max(st[c + 1][0], st[cc - 1][0])
		an[o[st[c + 1][0]]] = (m - (tmp2 - tmp1)) // 2 + tmp2
		an[o[st[cc - 1][0]]] = (m - (tmp2 - tmp1)) // 2 + tmp2

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = [int(x) for x in input().split()]
		o = Counter()
		for i in range(n):
			o[a[i]] = i
		an = [-1] * n
		s = input().split()
		xxx = []
		xyy = []
		for i in range(n):
			if a[i] % 2:
				xxx.append((a[i], s[i]))
			else:
				xyy.append((a[i], s[i]))
		xxx.sort()
		xyy.sort()
		func(xxx, an, o, m)
		func(xyy, an, o, m)
		print(*an)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for casen in range(t):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	lr = input().split()
	xlr = [[x[i], lr[i], i] for i in range(len(x))]
	maps = [0 for i in range(len(xlr))]
	xlr.sort(key=lambda x: x[0])
	for i in range(len(xlr)):
		maps[xlr[i][2]] = i
	unmatched = [[], []]
	out = [-1 for i in range(len(xlr))]
	for i in range(len(xlr)):
		parity = xlr[i][0] % 2
		if xlr[i][1] == 'R':
			unmatched[parity].append(i)
		elif len(unmatched[parity]) > 0:
			pair = unmatched[parity][-1]
			unmatched[parity].pop()
			if xlr[pair][1] == 'R':
				out[i] = (xlr[i][0] - xlr[pair][0]) // 2
				out[pair] = out[i]
			else:
				out[i] = xlr[pair][0] + (xlr[i][0] - xlr[pair][0]) // 2
				out[pair] = out[i]
		else:
			unmatched[parity].append(i)
	unmatched2 = [[], []]
	for p in range(2):
		for i in range(len(unmatched[p]) - 1, -1, -1):
			if len(unmatched2[p]) == 0:
				unmatched2[p].append(unmatched[p][i])
			else:
				cur = unmatched[p][i]
				prev = unmatched2[p][-1]
				unmatched2[p].pop()
				if xlr[cur][1] == 'L' and xlr[prev][1] == 'R':
					out[cur] = (xlr[cur][0] + (m - xlr[prev][0]) + m) // 2
					out[prev] = out[cur]
				else:
					out[cur] = m - xlr[prev][0] + (xlr[prev][0] - xlr[cur][0]) // 2
					out[prev] = out[cur]
	out2 = [out[maps[i]] for i in range(len(xlr))]
	print(' '.join(list(map(str, out2))))


import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
read = lambda : map(int, input().split())
from collections import deque
out = []
for _ in range(int(input())):
	(n, m) = read()
	x = list(read())
	s = input().split()
	y = []
	for i in range(n):
		y.append((x[i], i))
	y.sort()
	lo = deque()
	ro = []
	le = deque()
	re = []
	a = [-1] * n
	for (w, i) in y:
		if w & 1:
			if s[i] == b'L':
				if ro:
					v = ro.pop()
					a[i] = a[v] = (w - x[v]) // 2
				else:
					lo.append(i)
			else:
				ro.append(i)
		elif s[i] == b'L':
			if re:
				v = re.pop()
				a[i] = a[v] = (w - x[v]) // 2
			else:
				le.append(i)
		else:
			re.append(i)
	while len(lo) > 1:
		v = lo.popleft()
		w = lo.popleft()
		a[v] = a[w] = x[v] + (x[w] - x[v]) // 2
	while len(le) > 1:
		v = le.popleft()
		w = le.popleft()
		a[v] = a[w] = x[v] + (x[w] - x[v]) // 2
	while len(ro) > 1:
		v = ro.pop()
		w = ro.pop()
		a[v] = a[w] = m - x[v] + (x[v] - x[w]) // 2
	while len(re) > 1:
		v = re.pop()
		w = re.pop()
		a[v] = a[w] = m - x[v] + (x[v] - x[w]) // 2
	if lo and ro:
		v = lo.pop()
		w = ro.pop()
		a[v] = a[w] = (x[v] - x[w]) % (2 * m) // 2
	if le and re:
		v = le.pop()
		w = re.pop()
		a[v] = a[w] = (x[v] - x[w]) % (2 * m) // 2
	out.append(' '.join(map(str, a)))
print('\n'.join(out))


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

def input():
	return stdin.readline().strip()

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (fast, lambda : map(int, z().split()))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer, end='\n'):
	stdout.write(str(answer) + end)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]

def solve(robots, m, ans):
	robots.sort()
	stack = []
	for (x, dire, i) in robots:
		if dire == 'L':
			if not stack:
				stack.append((i, -x))
			else:
				(i2, x2) = stack[-1]
				ans[i] = ans[i2] = (x - x2) // 2
				stack.pop()
		else:
			stack.append((i, x))
	while len(stack) >= 2:
		(i1, x1) = stack[-1]
		stack.pop()
		x1 = m + (m - x1)
		(i2, x2) = stack[-1]
		stack.pop()
		ans[i1] = ans[i2] = (x1 - x2) // 2
for _ in range(int(z())):
	(n, m) = zzz()
	info = list(zip(zzz(), z().split()))
	robots = [[], []]
	for i in range(n):
		(x, dire) = info[i]
		robots[x % 2].append((x, dire, i))
	ans = [-1 for i in range(n)]
	solve(robots[0], m, ans)
	solve(robots[1], m, ans)
	print(*ans)


import heapq

class priority_queue:

	def __init__(self, mode=0):
		self.a = []
		self.mode = mode

	def push(self, x):
		if self.mode == 0:
			heapq.heappush(self.a, x)
		else:
			heapq.heappush(self.a, (-x[0], x[1], x[2]))

	def pop(self):
		if len(self.a) == 0:
			return None
		if self.mode == 0:
			return heapq.heappop(self.a)
		else:
			t = heapq.heappop(self.a)
			return (-t[0], t[1], t[2])

def work(a, m):
	a.sort()
	q = priority_queue(1)
	for i in range(len(a)):
		if a[i][1] == 'R':
			q.push(a[i])
		elif len(q.a) > 0:
			t = q.pop()
			ti = (a[i][0] - t[0]) // 2
			ans[t[2]] = ti
			ans[a[i][2]] = ti
	fir = -1
	for i in range(len(a)):
		if ans[a[i][2]] == -1 and a[i][1] == 'L':
			if fir == -1:
				fir = i
			else:
				ti = (a[i][0] + a[fir][0]) // 2
				ans[a[i][2]] = ti
				ans[a[fir][2]] = ti
				fir = -1
	fir = -1
	for i in range(len(a) - 1, -1, -1):
		if ans[a[i][2]] == -1 and a[i][1] == 'R':
			if fir == -1:
				fir = i
			else:
				ti = m - (a[i][0] + a[fir][0]) // 2
				ans[a[i][2]] = ti
				ans[a[fir][2]] = ti
				fir = -1
	fir = -1
	for i in range(len(a)):
		if ans[a[i][2]] == -1 and a[i][1] == 'L':
			fir = i
		if ans[a[i][2]] == -1 and a[i][1] == 'R' and (fir != -1):
			ti = m + (a[fir][0] - a[i][0]) // 2
			ans[a[i][2]] = ti
			ans[a[fir][2]] = ti
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	t2 = list(map(int, input().split()))
	t1 = input().split()
	ans = [-1] * (n + 1)
	a1 = []
	a2 = []
	for i in range(n):
		if t2[i] % 2 == 0:
			a1.append((t2[i], t1[i], i))
		else:
			a2.append((t2[i], t1[i], i))
	work(a1, m)
	work(a2, m)
	for i in range(n):
		print(ans[i])


import sys, io, os
try:
	Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
	Z = lambda : sys.stdin.readline().encode()
Y = lambda : map(int, Z().split())
from collections import deque as D
O = []
for _ in range(int(Z())):
	(n, m) = Y()
	x = [*Y()]
	s = Z().split()
	y = []
	for i in range(n):
		y.append((x[i], i))
	y.sort()
	lo = D()
	ro = []
	le = D()
	re = []
	a = [-1] * n
	for (w, i) in y:
		if w & 1:
			if s[i] == b'L':
				if ro:
					v = ro.pop()
					a[i] = a[v] = (w - x[v]) // 2
				else:
					lo.append(i)
			else:
				ro.append(i)
		elif s[i] == b'L':
			if re:
				v = re.pop()
				a[i] = a[v] = (w - x[v]) // 2
			else:
				le.append(i)
		else:
			re.append(i)
	while len(lo) > 1:
		v = lo.popleft()
		w = lo.popleft()
		a[v] = a[w] = x[v] + (x[w] - x[v]) // 2
	while len(le) > 1:
		v = le.popleft()
		w = le.popleft()
		a[v] = a[w] = x[v] + (x[w] - x[v]) // 2
	while len(ro) > 1:
		v = ro.pop()
		w = ro.pop()
		a[v] = a[w] = m - x[v] + (x[v] - x[w]) // 2
	while len(re) > 1:
		v = re.pop()
		w = re.pop()
		a[v] = a[w] = m - x[v] + (x[v] - x[w]) // 2
	if lo and ro:
		v = lo.pop()
		w = ro.pop()
		a[v] = a[w] = (x[v] - x[w]) % (2 * m) // 2
	if le and re:
		v = le.pop()
		w = re.pop()
		a[v] = a[w] = (x[v] - x[w]) % (2 * m) // 2
	O.append(' '.join(map(str, a)))
print('\n'.join(O))


import sys
input = sys.stdin.buffer.readline
for t in range(int(input())):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	S = list(input())
	X = [(A[i], S[i << 1], i) for i in range(N)]
	X.sort()
	ANS = [-1] * N
	Q = [[], []]
	Y = []
	for i in range(N):
		z = X[i][0] & 1
		if X[i][1] == 76:
			if len(Q[z]):
				x = Q[z][-1]
				y = X[i][2]
				del Q[z][-1]
				ANS[x] = abs(A[y] - A[x]) >> 1
				ANS[y] = ANS[x]
		else:
			Q[z].append(X[i][2])
	Y = [[[], []] for i in range(2)]
	for i in range(N):
		z = A[i] & 1
		if ANS[i] == -1:
			if S[i << 1] == 76:
				Y[z][0].append((A[i], i))
			else:
				Y[z][1].append((A[i], i))
	for i in range(2):
		for j in range(2):
			Y[i][j].sort()
	for i in range(2):
		for k in range(len(Y[i][0]) >> 1):
			ANS[Y[i][0][k << 1][1]] = Y[i][0][k << 1][0] + (Y[i][0][(k << 1) + 1][0] - Y[i][0][k << 1][0] >> 1)
			ANS[Y[i][0][(k << 1) + 1][1]] = ANS[Y[i][0][k << 1][1]]
		for k in range(len(Y[i][1]) >> 1):
			ANS[Y[i][1][-(k << 1) - 1][1]] = M - Y[i][1][-(k << 1) - 1][0] + (Y[i][1][-(k << 1) - 1][0] - Y[i][1][-(k << 1) - 2][0] >> 1)
			ANS[Y[i][1][-(k << 1) - 2][1]] = ANS[Y[i][1][-(k << 1) - 1][1]]
		if len(Y[i][0]) & 1 and len(Y[i][1]) & 1:
			(x, y) = (Y[i][0][-1], Y[i][1][0])
			ANS[x[1]] = x[0] + (M - y[0]) + M >> 1
			ANS[y[1]] = ANS[x[1]]
	print(*ANS)


t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split())
	p = list(map(int, input().split()))
	d = input().split()
	a = [(p[i], d[i], i) for i in range(n)]
	a = sorted(a)
	sol = [-1 for _ in range(n)]
	(odd, even) = ([], [])
	for i in range(n):
		q = odd if a[i][0] % 2 else even
		if len(q) == 0:
			q.append(a[i])
		elif q[-1][1] == 'R' and a[i][1] == 'L':
			sol[a[i][2]] = sol[q[-1][2]] = (a[i][0] - q[-1][0]) // 2
			q.pop()
		else:
			q.append(a[i])
	for q in (odd, even):
		while len(q) >= 2 and q[-2][1] == 'R':
			sol[q[-2][2]] = sol[q[-1][2]] = m - q[-1][0] + (q[-1][0] - q[-2][0]) // 2
			q.pop()
			q.pop()
		i = 1
		while i < len(q):
			if q[i][1] != 'L':
				break
			sol[q[i - 1][2]] = sol[q[i][2]] = q[i - 1][0] + (q[i][0] - q[i - 1][0]) // 2
			i += 2
		if i + 1 <= len(q):
			sol[q[-1][2]] = sol[q[-2][2]] = m - (q[-1][0] - q[-2][0]) // 2
	print(' '.join(map(str, sol)))


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
from random import *
from itertools import permutations
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from fractions import *
from math import sqrt, ceil, log2, gcd, cos, pi, floor
from copy import deepcopy
mod = 10 ** 9 + 7
mod2 = 998244353

def ps(n):
	cp = 0
	lk = 0
	arr = {}
	lk = 0
	ap = n
	cc = 0
	while n % 2 == 0:
		n = n // 2
		cc = 1
	if cc == 1:
		lk += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		cc = 0
		while n % ps == 0:
			n = n // ps
			cc = 1
		lk += 1 if cc == 1 else 0
	if n != 1:
		lk += 1
	if lk == 1:
		return False
	return True

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n):
		qlr = qlr * ip % mod
	for ij in range(1, r):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

def pda(n):
	list = []
	su = 0
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				list.append(i)
				su += i
			else:
				list.append(n // i)
				list.append(i)
				su += i
				su += n // i
	return su

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

def ii():
	return int(input())

def ilist():
	return [int(x) for x in input().strip().split()]

def islist():
	return list(map(str, input().split().rstrip()))

def inp():
	return input().strip()

def google(test):
	return 'Case #' + str(test) + ': '

def overlap(x1, y1, x2, y2):
	if x2 > y1:
		return y1 - x2
	if y1 > y2:
		return y2 - x2
	return y1 - x2

def dist(x1, y1, x2, y2):
	return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	ans = []
	for i in range(1, n + 1):
		if prime[i]:
			ans.append(i)
	return ans

def prod(arr):
	n = len(arr)
	k = 1
	for j in range(n):
		k *= arr[j]
	return k

def SumOfDigits(s):
	su = 0
	while s:
		su += s % 10
		s = s // 10
	return su

def std():
	return stdout.flush()

def finds(s):
	att = 0
	i = 1
	while i < len(s):
		att = int(s[:i])
		j = i
		cc = 0
		while j < len(s):
			att += 1
			sk = att
			news = str(sk)
			rr = len(news)
			if news == s[j:j + rr]:
				j += rr
			else:
				cc = 1
				break
		if cc == 0:
			return True
		i += 1
	return False
arr = []
for i in range(1, 10001):
	s = str(i)
	j = i
	while len(s) <= 7:
		j += 1
		s += str(j)
		arr.append(int(s))
arr.sort()

def subs(arr):
	res = set()
	pre = {0}
	for x in arr:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)

def sl(n):
	return n * (n + 1) // 2
t = ii()
for pl in range(t):
	(n, m) = ilist()
	arr = [[0] * 3 for i in range(n)]
	brr = ilist()
	crr = list(map(str, input().strip().split()))
	for i in range(n):
		arr[i][0] = brr[i]
		arr[i][1] = crr[i]
		arr[i][2] = i
	arr = sorted(arr, key=lambda x: x[0])
	oddr = []
	oddl = []
	evenr = []
	evenl = []
	time = [-1] * n
	for i in range(n):
		lx = arr[i]
		if lx[1] == 'L':
			if lx[0] % 2 == 0:
				if len(evenr) > 0:
					qx = evenr[-1]
					time[qx[1]] = time[lx[2]] = (lx[0] - qx[0]) // 2
					evenr.pop()
					continue
			elif len(oddr) > 0:
				qx = oddr[-1]
				time[qx[1]] = time[lx[2]] = (lx[0] - qx[0]) // 2
				oddr.pop()
				continue
			if lx[0] % 2 == 0:
				evenl.append([lx[0], lx[2]])
			else:
				oddl.append([lx[0], lx[2]])
		else:
			lx = arr[i]
			if lx[0] % 2 == 0:
				evenr.append([lx[0], lx[2]])
			else:
				oddr.append([lx[0], lx[2]])
	if len(evenl) > 0:
		i = 0
		while i < len(evenl) - 1:
			lx = evenl[i]
			px = evenl[i + 1]
			time[lx[1]] = time[px[1]] = (lx[0] + px[0]) // 2
			i += 2
	if len(oddl) > 0:
		i = 0
		while i < len(oddl) - 1:
			lx = oddl[i]
			px = oddl[i + 1]
			time[lx[1]] = time[px[1]] = (lx[0] + px[0]) // 2
			i += 2
	evenr = evenr[::-1]
	oddr = oddr[::-1]
	if len(evenr) > 0:
		i = 0
		while i < len(evenr) - 1:
			lx = evenr[i]
			px = evenr[i + 1]
			time[lx[1]] = time[px[1]] = (2 * m - lx[0] - px[0]) // 2
			i += 2
	if len(oddr) > 0:
		i = 0
		while i < len(oddr) - 1:
			lx = oddr[i]
			px = oddr[i + 1]
			time[lx[1]] = time[px[1]] = (2 * m - lx[0] - px[0]) // 2
			i += 2
	if len(evenr) % 2 != 0 and len(evenl) % 2 != 0:
		lx = evenr[-1]
		px = evenl[-1]
		maxer = max(m - lx[0], px[0])
		miner = min(m - lx[0], px[0])
		time[lx[1]] = time[px[1]] = maxer + (m - maxer + miner) // 2
	if len(oddr) % 2 != 0 and len(oddl) % 2 != 0:
		lx = oddr[-1]
		px = oddl[-1]
		maxer = max(m - lx[0], px[0])
		miner = min(m - lx[0], px[0])
		time[lx[1]] = time[px[1]] = maxer + (m - maxer + miner) // 2
	print(*time)


from io import BytesIO, IOBase
import sys
import math
import os
import heapq
from collections import defaultdict, deque
from math import ceil
from bisect import bisect_left, bisect_left
from time import perf_counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def mint():
	return map(int, input().split())

def mfloat():
	return map(float, input().split())

def intin():
	return int(input())

def solve():
	(n, m) = mint()
	(*a,) = mint()
	d = {a[i]: i for i in range(n)}
	ans = [-1] * n
	directions = input().split()
	bots = sorted(zip(a, directions))
	odds = [i for i in bots if i[0] % 2]
	evens = [i for i in bots if i[0] % 2 == 0]
	for parity in (evens, odds):
		starts = []
		collisions = []
		apparent_to_real = {}
		for i in parity:
			if i[1] == 'R':
				starts.append(i[0])
				apparent_to_real[i[0]] = i[0]
			elif starts:
				collisions.append([starts.pop(), i[0]])
				apparent_to_real[i[0]] = i[0]
			else:
				starts.append(-i[0])
				apparent_to_real[-i[0]] = i[0]
		while len(starts) > 1:
			left_idx = starts.pop()
			going_left = 2 * m - left_idx
			apparent_to_real[going_left] = left_idx
			going_right = starts.pop()
			collisions.append([going_right, going_left])
		for i in collisions:
			l = i[0]
			r = i[1]
			time = (r - l) // 2
			ans[d[apparent_to_real[l]]] = ans[d[apparent_to_real[r]]] = time
	print(*ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
start_time = perf_counter()
main()
print(perf_counter() - start_time, file=sys.stderr)


def solve(robots, ans, m):
	robots.sort()
	stack = []
	for (x, dire, i) in robots:
		if dire == 'L':
			if not stack:
				stack.append((i, -x))
			else:
				(i1, x1) = stack[-1]
				stack.pop()
				ans[i] = ans[i1] = (x - x1) // 2
		else:
			stack.append((i, x))
	while len(stack) >= 2:
		(i1, x1) = stack[-1]
		stack.pop()
		x1 = m + (m - x1)
		(i2, x2) = stack[-1]
		stack.pop()
		ans[i1] = ans[i2] = (x1 - x2) // 2
for i in range(int(input())):
	(n, m) = map(int, input().split())
	z = list(zip(map(int, input().split()), input().split()))
	robots = [[], []]
	for i in range(n):
		x = z[i]
		robots[z[i][0] & 1].append((z[i][0], z[i][1], i))
	ans = [-1] * n
	solve(robots[0], ans, m)
	solve(robots[1], ans, m)
	print(*ans)


import sys

def ni():
	return int(sys.stdin.readline())

def nis():
	return map(int, sys.stdin.readline().split())

def nia():
	return [*map(int, sys.stdin.readline().split())]

def ns():
	return sys.stdin.readline().rstrip()
from collections import deque
from functools import reduce
for T in range(ni()):
	(n, m) = nis()
	x = nia()
	LRs = input().strip().split()
	ans = [-1] * n
	p = [(x[i], LRs[i], i) for i in range(n)]
	p.sort()
	st = []
	for pi in p:
		(xi, lr, idx) = pi
		if xi % 2 == 0:
			continue
		if lr == 'R':
			st.append(pi)
			continue
		if st:
			(xiz, lrz, idxz) = st.pop()
			if lrz == 'R':
				t = (xi - xiz) // 2
				ans[idx] = t
				ans[idxz] = t
			else:
				t = (xi + xiz) // 2
				ans[idx] = t
				ans[idxz] = t
		else:
			st.append(pi)
	while st:
		(xi, lr, idx) = st.pop()
		if st:
			(xiz, lrz, idxz) = st.pop()
		else:
			break
		if lr == 'R' and lrz == 'R':
			t = (m - xi + m - xiz) // 2
			ans[idx] = t
			ans[idxz] = t
		else:
			t = (m - xi + xiz + m) // 2
			ans[idx] = t
			ans[idxz] = t
	st = []
	for pi in p:
		(xi, lr, idx) = pi
		if xi % 2 == 1:
			continue
		if lr == 'R':
			st.append(pi)
			continue
		if st:
			(xiz, lrz, idxz) = st.pop()
			if lrz == 'R':
				t = (xi - xiz) // 2
				ans[idx] = t
				ans[idxz] = t
			else:
				t = (xi + xiz) // 2
				ans[idx] = t
				ans[idxz] = t
		else:
			st.append(pi)
	while st:
		(xi, lr, idx) = st.pop()
		if st:
			(xiz, lrz, idxz) = st.pop()
		else:
			break
		if lr == 'R' and lrz == 'R':
			t = (m - xi + m - xiz) // 2
			ans[idx] = t
			ans[idxz] = t
		else:
			t = (m - xi + xiz + m) // 2
			ans[idx] = t
			ans[idxz] = t
	print(' '.join(map(str, ans)))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
MOD = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	(n, m) = map(int, input().split())
	x = [*map(int, input().split())]
	di = input().split()
	res = [(s, d) for (s, d) in zip(x, di)]
	order = list(range(n))
	order.sort(key=lambda k: res[k][0])
	ans = [-1] * n
	ost = []
	est = []
	for i in order:
		(s, d) = res[i]
		if s & 1:
			if d == 'L':
				if not ost:
					ost.append((-s, i))
				else:
					(p, ind) = ost.pop()
					ans[ind] = ans[i] = (s - p) // 2
			else:
				ost.append((s, i))
		elif d == 'L':
			if not est:
				est.append((-s, i))
			else:
				(p, ind) = est.pop()
				ans[ind] = ans[i] = (s - p) // 2
		else:
			est.append((s, i))
	while len(ost) > 1:
		(p2, se) = ost.pop()
		(p1, fi) = ost.pop()
		p2 = 2 * m - p2
		ans[se] = ans[fi] = (p2 - p1) // 2
	while len(est) > 1:
		(p2, se) = est.pop()
		(p1, fi) = est.pop()
		p2 = 2 * m - p2
		ans[se] = ans[fi] = (p2 - p1) // 2
	print(*ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, m) = inp()
	arr = list(inp())
	s = input().split(' ')
	temp = []
	for i in range(n):
		temp.append([arr[i], s[i], i])
	temp.sort()
	arr = list(temp)
	even = []
	odd = []
	for i in range(n):
		if arr[i][0] % 2 == 0:
			even.append(arr[i])
		else:
			odd.append(arr[i])
	ans = [-1] * n
	mark = dd(bool)
	nn = len(even)
	i = 0
	stack = []
	while i < nn:
		if even[i][1] == 'R':
			stack.append(even[i])
		elif len(stack) == 0:
			pass
		else:
			val = (even[i][0] - stack[-1][0]) // 2
			pos1 = even[i][2]
			pos2 = stack[-1][2]
			ans[pos1] = val
			ans[pos2] = val
			mark[pos1] = True
			mark[pos2] = True
			stack.pop()
		i += 1
	rem = []
	left = []
	right = []
	for i in range(nn):
		ele = even[i][2]
		if mark[ele]:
			pass
		elif even[i][1] == 'L':
			left.append(even[i])
		else:
			right.append(even[i])
	for i in range(1, len(left), 2):
		time = left[i - 1][0] - 0
		val = (left[i][0] - left[i - 1][0]) // 2
		time += val
		pos1 = left[i][2]
		pos2 = left[i - 1][2]
		ans[pos1] = time
		ans[pos2] = time
		mark[pos1] = True
		mark[pos2] = True
	rem = []
	for i in range(len(left)):
		pos = left[i][2]
		if mark[pos]:
			pass
		else:
			rem.append(left[i])
	left = list(rem)
	i = len(right) - 1
	while i - 1 >= 0:
		time = m - right[i][0]
		val = (right[i][0] - right[i - 1][0]) // 2
		time += val
		pos1 = right[i][2]
		pos2 = right[i - 1][2]
		ans[pos1] = time
		ans[pos2] = time
		mark[pos1] = True
		mark[pos2] = True
		i -= 2
	rem = []
	for i in range(len(right)):
		pos = right[i][2]
		if mark[pos]:
			pass
		else:
			rem.append(right[i])
	right = list(rem)
	if len(left) != 0 and len(right) != 0:
		val1 = left[0][0]
		val2 = right[0][0]
		diff1 = val1 - 0
		diff2 = m - val2
		if diff1 <= diff2:
			time = 0
			val2 = m
			val1 = 0
			time += diff2
			diff2 -= diff1
			val1 += diff2
			val = abs(val1 - val2) // 2
			time += val
			pos1 = left[0][2]
			pos2 = right[0][2]
			ans[pos1] = time
			ans[pos2] = time
		else:
			time = 0
			val1 = 0
			val2 = m
			time += diff1
			diff1 -= diff2
			val2 -= diff1
			val = abs(val1 - val2) // 2
			time += val
			pos1 = left[0][2]
			pos2 = right[0][2]
			ans[pos1] = time
			ans[pos2] = time
	even = list(odd)
	mark = dd(bool)
	nn = len(even)
	i = 0
	stack = []
	while i < nn:
		if even[i][1] == 'R':
			stack.append(even[i])
		elif len(stack) == 0:
			pass
		else:
			val = (even[i][0] - stack[-1][0]) // 2
			pos1 = even[i][2]
			pos2 = stack[-1][2]
			ans[pos1] = val
			ans[pos2] = val
			mark[pos1] = True
			mark[pos2] = True
			stack.pop()
		i += 1
	rem = []
	left = []
	right = []
	for i in range(nn):
		ele = even[i][2]
		if mark[ele]:
			pass
		elif even[i][1] == 'L':
			left.append(even[i])
		else:
			right.append(even[i])
	for i in range(1, len(left), 2):
		time = left[i - 1][0] - 0
		val = (left[i][0] - left[i - 1][0]) // 2
		time += val
		pos1 = left[i][2]
		pos2 = left[i - 1][2]
		ans[pos1] = time
		ans[pos2] = time
		mark[pos1] = True
		mark[pos2] = True
	rem = []
	for i in range(len(left)):
		pos = left[i][2]
		if mark[pos]:
			pass
		else:
			rem.append(left[i])
	left = list(rem)
	i = len(right) - 1
	while i - 1 >= 0:
		time = m - right[i][0]
		val = (right[i][0] - right[i - 1][0]) // 2
		time += val
		pos1 = right[i][2]
		pos2 = right[i - 1][2]
		ans[pos1] = time
		ans[pos2] = time
		mark[pos1] = True
		mark[pos2] = True
		i -= 2
	rem = []
	for i in range(len(right)):
		pos = right[i][2]
		if mark[pos]:
			pass
		else:
			rem.append(right[i])
	right = list(rem)
	if len(left) != 0 and len(right) != 0:
		val1 = left[0][0]
		val2 = right[0][0]
		diff1 = val1 - 0
		diff2 = m - val2
		if diff1 <= diff2:
			time = 0
			val2 = m
			val1 = 0
			time += diff2
			diff2 -= diff1
			val1 += diff2
			val = abs(val1 - val2) // 2
			time += val
			pos1 = left[0][2]
			pos2 = right[0][2]
			ans[pos1] = time
			ans[pos2] = time
		else:
			time = 0
			val1 = 0
			val2 = m
			time += diff1
			diff1 -= diff2
			val2 -= diff1
			val = abs(val1 - val2) // 2
			time += val
			pos1 = left[0][2]
			pos2 = right[0][2]
			ans[pos1] = time
			ans[pos2] = time
	print(*ans)


from collections import defaultdict

def red(lis, left=True):
	while len(lis) > 1:
		v1 = lis.pop()
		v2 = lis.pop()
		cost = (v1 + v2) // 2 if left else (2 * m - v1 - v2) // 2
		(ans[v1], ans[v2]) = (cost, cost)
	return lis

def start(ini, di):
	for i in range(n):
		(val, curr) = (l[i], d[i])
		if val % 2 != ini:
			continue
		if curr == 'L':
			if di['R']:
				pos = di['R'].pop()
				cost = (val - pos) // 2
				(ans[pos], ans[val]) = (cost, cost)
			else:
				di['L'].append(val)
		else:
			di['R'].append(val)
	di['L'] = red(di['L'][::-1])
	di['R'] = red(di['R'], False)
	if di['L'] and di['R']:
		v1 = di['L'].pop()
		v2 = di['R'].pop()
		cost = (m + (m - v2) + v1) // 2
		(ans[v1], ans[v2]) = (cost, cost)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	initial = list(map(int, input().split()))
	(l, d) = zip(*sorted(zip(initial, input().split())))
	ans = defaultdict(lambda : -1)
	evens = defaultdict(list)
	odds = defaultdict(list)
	start(0, evens)
	start(1, odds)
	for i in range(n):
		initial[i] = ans[initial[i]]
	print(*initial)


import os, sys
from io import BytesIO, IOBase
from collections import deque, Counter, defaultdict as dft
from heapq import heappop, heappush
from math import log, sqrt, factorial, cos, tan, sin, radians, log2, ceil, floor
from bisect import bisect, bisect_left, bisect_right
from decimal import *
import sys, threading
from itertools import permutations, combinations
from copy import deepcopy
input = sys.stdin.readline
ii = lambda : int(input())
si = lambda : input().rstrip()
mp = lambda : map(int, input().split())
ms = lambda : map(str, input().strip().split(' '))
ml = lambda : list(mp())
mf = lambda : map(float, input().split())
alphs = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	(n, m) = mp()
	arr = ml()
	dir = list(ms())
	si = [i for i in range(n)]
	si = sorted(si, key=lambda x: arr[x])
	sdir = [dir[idx] for idx in si]
	dir = sdir
	arr.sort()
	ro = deque([])
	re = deque([])
	rem_lo = deque([])
	rem_le = deque([])
	res = [-1] * n
	for i in range(n):
		if dir[i] == 'L':
			if arr[i] % 2:
				if ro:
					idx = ro.pop()
					t = abs(arr[i] - arr[idx]) // 2
					res[idx] = t
					res[i] = t
				elif rem_lo:
					idx = rem_lo.pop()
					t = abs(arr[i] - arr[idx]) // 2 + arr[idx]
					res[idx] = t
					res[i] = t
				else:
					rem_lo.append(i)
			elif re:
				idx = re.pop()
				t = abs(arr[i] - arr[idx]) // 2
				res[idx] = t
				res[i] = t
			elif rem_le:
				idx = rem_le.pop()
				t = abs(arr[i] - arr[idx]) // 2 + arr[idx]
				res[idx] = t
				res[i] = t
			else:
				rem_le.append(i)
		elif arr[i] % 2:
			ro.append(i)
		else:
			re.append(i)
	while len(ro) > 1:
		i = ro.pop()
		idx = ro.pop()
		t = abs(arr[i] - arr[idx]) // 2 + m - arr[i]
		res[idx] = t
		res[i] = t
	while len(re) > 1:
		i = re.pop()
		idx = re.pop()
		t = abs(arr[i] - arr[idx]) // 2 + m - arr[i]
		res[idx] = t
		res[i] = t
	if rem_lo and ro:
		i = rem_lo.pop()
		idx = ro.pop()
		x1 = arr[i]
		x2 = arr[idx]
		if x1 + x2 < m:
			t = (x1 + x2) // 2 + (m - x2)
			res[idx] = t
			res[i] = t
		else:
			t = (2 * m - (x1 + x2)) // 2 + x1
			res[idx] = t
			res[i] = t
	if rem_le and re:
		i = rem_le.pop()
		idx = re.pop()
		x1 = arr[i]
		x2 = arr[idx]
		if x1 + x2 < m:
			t = (x1 + x2) // 2 + (m - x2)
			res[idx] = t
			res[i] = t
		else:
			t = (2 * m - (x1 + x2)) // 2 + x1
			res[idx] = t
			res[i] = t
	sres = [-1] * n
	for i in range(n):
		sres[si[i]] = res[i]
	print(*sres)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
tc = 1
tc = ii()
for i in range(tc):
	solve()


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil, log2
from bisect import bisect_right
mod = 10 ** 9 + 7

def dis_type_1(x, y):
	return (x - y) // 2

def dis_type_2(x, y):
	return (x + y) // 2

def solve(a):
	st_rig = []
	st_left = []
	for i in range(len(a)):
		if a[i][1] == 'R':
			st_rig.append(a[i])
		elif st_rig:
			t = dis_type_1(a[i][0], st_rig[-1][0])
			ans[a[i][2]] = t
			ans[st_rig[-1][2]] = t
			st_rig.pop()
		elif st_left:
			t = dis_type_2(st_left[-1][0], a[i][0])
			ans[a[i][2]] = t
			ans[st_left[-1][2]] = t
			st_left.pop()
		else:
			st_left.append(a[i])
	while len(st_rig) >= 2:
		x = m - st_rig[-1][0]
		y = m - st_rig[-2][0]
		t = dis_type_2(x, y)
		ans[st_rig[-1][2]] = t
		ans[st_rig[-2][2]] = t
		st_rig.pop()
		st_rig.pop()
	if st_rig and st_left:
		y = m - st_rig[-1][0]
		x = st_left[-1][0]
		t = (x + y + m) // 2
		ans[st_left[-1][2]] = t
		ans[st_rig[-1][2]] = t
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = [[i, v, id] for (id, (i, v)) in enumerate(zip(map(int, input().split()), input().split()))]
	ev = []
	ev2 = []
	for i in range(n):
		if ar[i][0] % 2 == 0:
			ev.append(ar[i])
		else:
			ev2.append(ar[i])
	ans = [-1] * n
	ev.sort()
	solve(ev)
	ev = []
	ev2.sort()
	solve(ev2)
	print(*ans)


import sys
for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	temp = [x for x in input().split()]
	for i in range(n):
		arr[i] = tuple([arr[i], temp[i], i])
	arr.sort()
	(odd, even) = ([], [])
	for i in range(n):
		if arr[i][0] % 2:
			odd.append(tuple([arr[i][2], arr[i][0], arr[i][1]]))
		else:
			even.append(tuple([arr[i][2], arr[i][0], arr[i][1]]))
	ans = [-1 for i in range(n)]
	s = []
	temp = []
	for i in odd:
		if i[2] == 'R':
			s.append([i[1], i[0], i[2]])
		elif s:
			curr = s.pop()
			ans[curr[1]] = (i[1] - curr[0]) // 2
			ans[i[0]] = (i[1] - curr[0]) // 2
		else:
			temp.append([i[1], i[0], i[2]])
	i = 0
	temp = temp[::-1]
	while temp:
		a = temp.pop()
		if temp:
			b = temp.pop()
			ans[a[1]] = (b[0] - a[0]) // 2 + a[0]
			ans[b[1]] = (b[0] - a[0]) // 2 + a[0]
		else:
			temp.append(a)
			break
	while s:
		a = s.pop()
		if s:
			b = s.pop()
			ans[a[1]] = (a[0] - b[0]) // 2 + m - a[0]
			ans[b[1]] = (a[0] - b[0]) // 2 + m - a[0]
		else:
			s.append(a)
			break
	if s and temp:
		a = temp.pop()
		b = s.pop()
		if a[0] > m - b[0]:
			ans[a[1]] = (m - (a[0] - (m - b[0]))) // 2 + a[0]
			ans[b[1]] = (m - (a[0] - (m - b[0]))) // 2 + a[0]
		else:
			ans[a[1]] = (m - (m - b[0] - a[0])) // 2 + (m - b[0])
			ans[b[1]] = (m - (m - b[0] - a[0])) // 2 + (m - b[0])
	temp = []
	s = []
	for i in even:
		if i[2] == 'R':
			s.append([i[1], i[0], i[2]])
		elif s:
			curr = s.pop()
			ans[curr[1]] = (i[1] - curr[0]) // 2
			ans[i[0]] = (i[1] - curr[0]) // 2
		else:
			temp.append([i[1], i[0], i[2]])
	i = 0
	temp = temp[::-1]
	while temp:
		a = temp.pop()
		if temp:
			b = temp.pop()
			ans[a[1]] = (b[0] - a[0]) // 2 + a[0]
			ans[b[1]] = (b[0] - a[0]) // 2 + a[0]
		else:
			temp.append(a)
			break
	while s:
		a = s.pop()
		if s:
			b = s.pop()
			ans[a[1]] = (a[0] - b[0]) // 2 + m - a[0]
			ans[b[1]] = (a[0] - b[0]) // 2 + m - a[0]
		else:
			s.append(a)
			break
	if s and temp:
		a = temp.pop()
		b = s.pop()
		if a[0] > m - b[0]:
			ans[a[1]] = (m - (a[0] - (m - b[0]))) // 2 + a[0]
			ans[b[1]] = (m - (a[0] - (m - b[0]))) // 2 + a[0]
		else:
			ans[a[1]] = (m - (m - b[0] - a[0])) // 2 + (m - b[0])
			ans[b[1]] = (m - (m - b[0] - a[0])) // 2 + (m - b[0])
	print(*ans)


import sys
input = sys.stdin.readline
from math import gcd

def main():
	(n, m) = map(int, input().split())
	xlst = list(map(int, input().split()))
	Slst = list(input().strip().split())
	xs = [(x, s, i) for (i, (x, s)) in enumerate(zip(xlst, Slst))]
	xs.sort()
	odd = []
	even = []
	ans = [-1] * n
	for (x, s, i) in xs:
		if s == 'R':
			if x % 2 == 0:
				even.append((i, x))
			else:
				odd.append((i, x))
		elif x % 2 == 0:
			if even:
				(j, y) = even.pop()
				ans[i] = ans[j] = (x - y) // 2
			else:
				even.append((i, -x))
		elif odd:
			(j, y) = odd.pop()
			ans[i] = ans[j] = (x - y) // 2
		else:
			odd.append((i, -x))
	while len(even) >= 2:
		(i, x) = even.pop()
		(j, y) = even.pop()
		ans[i] = ans[j] = (x - y) // 2 + m - x
	while len(odd) >= 2:
		(i, x) = odd.pop()
		(j, y) = odd.pop()
		ans[i] = ans[j] = (x - y) // 2 + m - x
	print(*ans)
for _ in range(int(input())):
	main()


from collections import defaultdict, deque
import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = list(map(str, input().split()))
	b = [(a[i], s[i], i) for i in range(n)]
	b.sort(key=lambda x: x[0])
	ans = [-1] * n
	even = deque([])
	odd = deque([])
	for i in range(n):
		if b[i][0] % 2 == 0:
			even.append(b[i])
		else:
			odd.append(b[i])
	poped_even_l = deque()
	poped_even_r = deque()
	while even:
		(val, sign, idx) = even.popleft()
		if sign == 'R':
			poped_even_r.append((val, sign, idx))
		elif poped_even_r:
			(lx, _, idxl) = (val, sign, idx)
			(rx, _, idxr) = poped_even_r.pop()
			time = abs(rx - lx) // 2
			ans[idxl] = ans[idxr] = time
			continue
		else:
			poped_even_l.append((val, sign, idx))
	while poped_even_l:
		(val0, _, idx0) = poped_even_l.popleft()
		if poped_even_l:
			(val1, _, idx1) = poped_even_l.popleft()
			time = val0 + abs(val1 - val0) // 2
			ans[idx0] = ans[idx1] = time
			continue
		else:
			poped_even_l.append((val0, -1, idx0))
			break
	while poped_even_r:
		(val1, _, idx1) = poped_even_r.pop()
		if poped_even_r:
			(val0, _, idx0) = poped_even_r.pop()
			(distance0, distance1) = (m - val0, m - val1)
			time = distance1 + abs(distance1 - distance0) // 2
			ans[idx0] = ans[idx1] = time
			continue
		else:
			poped_even_r.append((val1, -1, idx1))
			break
	if not (poped_even_l and poped_even_r):
		poped_even_l.clear()
		poped_even_r.clear()
	else:
		(val0, _, idx0) = poped_even_l.pop()
		(val1, _, idx1) = poped_even_r.pop()
		(distance0, distance_middle, distance1) = (val0, abs(val1 - val0), m - val1)
		time = 2 * (distance0 + distance1) + distance_middle
		time = time // 2
		ans[idx0] = ans[idx1] = time
	even = odd.copy()
	while even:
		(val, sign, idx) = even.popleft()
		if sign == 'R':
			poped_even_r.append((val, sign, idx))
		elif poped_even_r:
			(lx, _, idxl) = (val, sign, idx)
			(rx, _, idxr) = poped_even_r.pop()
			time = abs(rx - lx) // 2
			ans[idxl] = ans[idxr] = time
			continue
		else:
			poped_even_l.append((val, sign, idx))
	while poped_even_l:
		(val0, _, idx0) = poped_even_l.popleft()
		if poped_even_l:
			(val1, _, idx1) = poped_even_l.popleft()
			time = val0 + abs(val1 - val0) // 2
			ans[idx0] = ans[idx1] = time
			continue
		else:
			poped_even_l.append((val0, -1, idx0))
			break
	while poped_even_r:
		(val1, _, idx1) = poped_even_r.pop()
		if poped_even_r:
			(val0, _, idx0) = poped_even_r.pop()
			(distance0, distance1) = (m - val0, m - val1)
			time = distance1 + abs(distance1 - distance0) // 2
			ans[idx0] = ans[idx1] = time
			continue
		else:
			poped_even_r.append((val1, -1, idx1))
			break
	if not (poped_even_l and poped_even_r):
		poped_even_l.clear()
		poped_even_r.clear()
	else:
		(val0, _, idx0) = poped_even_l.pop()
		(val1, _, idx1) = poped_even_r.pop()
		(distance0, distance_middle, distance1) = (val0, val1 - val0, m - val1)
		time = 2 * (distance0 + distance1) + distance_middle
		time = time // 2
		ans[idx0] = ans[idx1] = time
	print(*ans)
	return 0

def main():
	t = int(input())
	for i in range(t):
		slv()
	return 0
main()


from collections import deque
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	c = input().split()
	ans = [-1] * n
	even = []
	odd = []
	x = 0
	y = 0
	for i in range(n):
		if l[i] % 2:
			odd.append([l[i], 0, i, c[i]])
			x += 1
		else:
			even.append([l[i], 0, i, c[i]])
			y += 1
	del l
	del c
	even.sort()
	odd.sort()
	d = deque()
	d1 = deque()
	for i in range(x - 1, -1, -1):
		if odd[i][-1] == 'R':
			if d:
				x = d.popleft()
				ans[odd[i][2]] = ans[x[2]] = abs(odd[i][0] - x[0]) // 2
				odd[i][1] = 1
			else:
				d1.appendleft(odd[i])
		else:
			d.appendleft(odd[i])
	d3 = deque()
	d2 = deque()
	for i in range(y - 1, -1, -1):
		if even[i][-1] == 'R':
			if d2:
				x = d2.popleft()
				ans[even[i][2]] = ans[x[2]] = abs(even[i][0] - x[0]) // 2
				even[i][1] = 1
			else:
				d3.appendleft(even[i])
		else:
			d2.appendleft(even[i])
	(even, odd) = ([], [])
	while d:
		x = d.popleft()
		f = 0
		if d:
			f = 1
			y = d.popleft()
			ans[x[2]] = ans[y[2]] = abs(y[0] + x[0]) // 2
		else:
			odd.append(x)
	while d2:
		x = d2.popleft()
		if d2:
			f = 1
			y = d2.popleft()
			ans[x[2]] = ans[y[2]] = abs(y[0] + x[0]) // 2
		else:
			even.append(x)
	while d1:
		x = d1.pop()
		f = 0
		if d1:
			f = 1
			y = d1.pop()
			ans[x[2]] = ans[y[2]] = abs(m - y[0] + m - x[0]) // 2
		else:
			odd.append(x)
	while d3:
		x = d3.pop()
		f = 0
		if d3:
			f = 1
			y = d3.pop()
			ans[x[2]] = ans[y[2]] = abs(m - y[0] + m - x[0]) // 2
		else:
			even.append(x)
	if len(even) > 1:
		even.sort(key=lambda x: x[-1])
		x = even[0]
		y = even[1]
		ans[x[2]] = ans[y[2]] = abs(y[0] - x[0]) // 2 + (m - y[0] + x[0])
	if len(odd) > 1:
		odd.sort(key=lambda x: x[-1])
		x = odd[0]
		y = odd[1]
		ans[x[2]] = ans[y[2]] = abs(y[0] - x[0]) // 2 + (m - y[0] + x[0])
	print(*ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	X = list(map(int, input().split()))
	S = list(map(str, input().split()))
	even = []
	odd = []
	for i in range(n):
		if X[i] % 2 == 0:
			even.append((X[i], S[i], i))
		else:
			odd.append((X[i], S[i], i))
	even.sort()
	odd.sort()
	ret = [-1] * n
	stack = []
	for (x, s, idx) in even:
		if s == 'R':
			stack.append((x, idx))
		elif not stack:
			stack.append((-x, idx))
		else:
			(col, pre_idx) = stack.pop()
			time = abs(x - col) // 2
			ret[pre_idx] = time
			ret[idx] = time
	while len(stack) >= 2:
		(first, f_idx) = stack.pop()
		(second, s_idx) = stack.pop()
		time = ((m - first) * 2 + (first - second)) // 2
		ret[f_idx] = time
		ret[s_idx] = time
	stack = []
	for (x, s, idx) in odd:
		if s == 'R':
			stack.append((x, idx))
		elif not stack:
			stack.append((-x, idx))
		else:
			(col, pre_idx) = stack.pop()
			time = abs(x - col) // 2
			ret[pre_idx] = time
			ret[idx] = time
	while len(stack) >= 2:
		(first, f_idx) = stack.pop()
		(second, s_idx) = stack.pop()
		time = ((m - first) * 2 + (first - second)) // 2
		ret[f_idx] = time
		ret[s_idx] = time
	print(*ret)


import math
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def process(s):
	b = []
	for j in s:
		b.append(j)
	return b
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	b = list(map(int, input().split()))
	pos = list(map(str, input().split()))
	ro = []
	re = []
	lo = []
	le = []
	val = [-1 for i in range(n)]
	l = defaultdict(lambda : 0)
	for j in range(n):
		if pos[j] == 'R':
			if b[j] % 2 == 0:
				re.append([b[j], j])
				l['re'] += 1
			else:
				ro.append([b[j], j])
				l['ro'] += 1
		elif b[j] % 2 == 0:
			le.append([b[j], j])
			l['le'] += 1
		else:
			lo.append([b[j], j])
			l['lo'] += 1
	re.sort()
	ro.sort()
	le.sort()
	lo.sort()
	l1 = l['ro']
	l2 = l['lo']
	i1 = l1 - 1
	st = []
	j1 = l2 - 1
	while i1 >= 0 and j1 >= 0:
		while j1 >= 0 and ro[i1][0] < lo[j1][0]:
			st.append([lo[j1][0], lo[j1][1]])
			j1 += -1
		try:
			v1 = st.pop()
			v = (v1[0] - ro[i1][0]) // 2
			val[ro[i1][1]] = v
			val[v1[1]] = v
			i1 += -1
		except:
			i1 += -1
	while i1 >= 0:
		try:
			v1 = st.pop()
			v = (v1[0] - ro[i1][0]) // 2
			val[ro[i1][1]] = v
			val[v1[1]] = v
			i1 += -1
		except:
			i1 += -1
	l1 = l['re']
	l2 = l['le']
	i1 = l1 - 1
	st = []
	j1 = l2 - 1
	while i1 >= 0 and j1 >= 0:
		while j1 >= 0 and re[i1][0] < le[j1][0]:
			st.append([le[j1][0], le[j1][1]])
			j1 += -1
		try:
			v1 = st.pop()
			v = (v1[0] - re[i1][0]) // 2
			val[re[i1][1]] = v
			val[v1[1]] = v
			i1 += -1
		except:
			i1 += -1
	while i1 >= 0:
		try:
			v1 = st.pop()
			v = (v1[0] - re[i1][0]) // 2
			val[re[i1][1]] = v
			val[v1[1]] = v
			i1 += -1
		except:
			i1 += -1
	i1 = 0
	j1 = 1
	l1 = l['lo']
	while i1 < l1 and j1 < l1:
		ind1 = lo[i1][1]
		ind2 = lo[j1][1]
		if j1 >= l1:
			break
		if i1 >= j1:
			j1 = i1 + 1
		elif val[ind1] != -1:
			i1 += 1
		elif val[ind2] != -1:
			j1 += 1
		else:
			ind1 = lo[i1][1]
			ind2 = lo[j1][1]
			v = (lo[j1][0] + lo[i1][0]) // 2
			val[ind1] = v
			val[ind2] = v
			i1 = j1 + 1
			j1 = i1 + 1
	i1 = 0
	j1 = 1
	l1 = l['le']
	while i1 < l1 and j1 < l1:
		ind1 = le[i1][1]
		ind2 = le[j1][1]
		if j1 >= l1:
			break
		if i1 >= j1:
			j1 = i1 + 1
		elif val[ind1] != -1:
			i1 += 1
		elif val[ind2] != -1:
			j1 += 1
		else:
			ind1 = le[i1][1]
			ind2 = le[j1][1]
			v = (le[j1][0] + le[i1][0]) // 2
			val[ind1] = v
			val[ind2] = v
			i1 = j1 + 1
			j1 = i1 + 1
	l1 = l['ro']
	i1 = l1 - 1
	j1 = l1 - 2
	while i1 >= 0 and j1 >= 0:
		ind1 = ro[i1][1]
		ind2 = ro[j1][1]
		if j1 < 0:
			break
		if j1 >= i1:
			j1 = i1 - 1
		elif val[ind1] != -1:
			i1 += -1
		elif val[ind2] != -1:
			j1 += -1
		else:
			ind1 = ro[i1][1]
			ind2 = ro[j1][1]
			v = m - (ro[j1][0] + ro[i1][0]) // 2
			val[ind1] = v
			val[ind2] = v
			i1 = j1 - 1
			j1 = i1 - 1
	l1 = l['re']
	i1 = l1 - 1
	j1 = l1 - 2
	while i1 >= 0 and j1 >= 0:
		ind1 = re[i1][1]
		ind2 = re[j1][1]
		if j1 < -1:
			break
		if j1 >= i1:
			j1 = i1 - 1
		elif val[ind1] != -1:
			i1 += -1
		elif val[ind2] != -1:
			j1 += -1
		else:
			ind1 = re[i1][1]
			ind2 = re[j1][1]
			v = m - (re[j1][0] + re[i1][0]) // 2
			val[ind1] = v
			val[ind2] = v
			i1 = j1 - 1
			j1 = i1 - 1
	l1 = l['re']
	l2 = l['le']
	i1 = l1 - 1
	j1 = 0
	while i1 >= 0 and j1 < l2:
		if re[i1][0] < le[j1][0]:
			break
		ind1 = re[i1][1]
		ind2 = le[j1][1]
		if val[ind1] != -1:
			i1 += -1
		elif val[ind2] != -1:
			j1 += 1
		else:
			ind1 = re[i1][1]
			ind2 = le[j1][1]
			v = m - (re[i1][0] - le[j1][0]) // 2
			val[ind1] = v
			val[ind2] = v
			i1 += -1
			j1 += 1
	l1 = l['ro']
	l2 = l['lo']
	i1 = l1 - 1
	j1 = 0
	while i1 >= 0 and j1 < l2:
		if ro[i1][0] < lo[j1][0]:
			break
		ind1 = ro[i1][1]
		ind2 = lo[j1][1]
		if val[ind1] != -1:
			i1 += -1
		elif val[ind2] != -1:
			j1 += 1
		else:
			ind1 = ro[i1][1]
			ind2 = lo[j1][1]
			v = m - (ro[i1][0] - lo[j1][0]) // 2
			val[ind1] = v
			val[ind2] = v
			i1 += -1
			j1 += 1
	print(*val)


import sys
pl = 1
sys.setrecursionlimit(10 ** 5)
if pl:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('outpt.txt', 'w')

def li():
	return [int(xxx) for xxx in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def ff():
	sys.stdout.flush()
t = fi()
while t > 0:
	t -= 1
	(n, m) = mi()
	a = li()
	b = list(input().split())
	c = []
	d = []
	for i in range(n):
		if a[i] % 2:
			c.append([a[i], b[i], i])
		else:
			d.append([a[i], b[i], i])
	c.sort()
	d.sort()
	st = []
	ans = [-1] * n
	for i in range(len(c)):
		if len(st) == 0:
			st.append(c[i])
		elif st[-1][1] == 'R' and c[i][1] == 'L':
			ans[st[-1][2]] = ans[c[i][2]] = abs(c[i][0] - st[-1][0]) // 2
			st.pop()
		else:
			st.append(c[i])
	i = 0
	p = []
	q = []
	r = []
	for i in range(len(st)):
		if st[i][1] == 'L':
			p.append(st[i])
		else:
			q.append(st[i])
	if len(p) % 2:
		r.append(p[-1])
		p.pop()
	if len(q) % 2:
		r.append(q[0])
		q.pop(0)
	for i in range(0, len(p), 2):
		ans[p[i][2]] = ans[p[i + 1][2]] = p[i][0] + abs(p[i][0] - p[i + 1][0]) // 2
	for i in range(len(q) - 2, -1, -2):
		ans[q[i][2]] = ans[q[i + 1][2]] = m - q[i + 1][0] + abs(q[i][0] - q[i + 1][0]) // 2
	if len(r) > 1:
		ans[r[-1][2]] = ans[r[-2][2]] = m - abs(r[0][0] - r[1][0]) // 2
	st = []
	for i in range(len(d)):
		if len(st) == 0:
			st.append(d[i])
		elif st[-1][1] == 'R' and d[i][1] == 'L':
			ans[st[-1][2]] = ans[d[i][2]] = abs(d[i][0] - st[-1][0]) // 2
			st.pop()
		else:
			st.append(d[i])
	p = []
	q = []
	r = []
	for i in range(len(st)):
		if st[i][1] == 'L':
			p.append(st[i])
		else:
			q.append(st[i])
	if len(p) % 2:
		r.append(p[-1])
		p.pop()
	if len(q) % 2:
		r.append(q[0])
		q.pop(0)
	for i in range(0, len(p), 2):
		ans[p[i][2]] = ans[p[i + 1][2]] = p[i][0] + abs(p[i][0] - p[i + 1][0]) // 2
	for i in range(len(q) - 2, -1, -2):
		ans[q[i][2]] = ans[q[i + 1][2]] = m - q[i + 1][0] + abs(q[i][0] - q[i + 1][0]) // 2
	if len(r) > 1:
		ans[r[-1][2]] = ans[r[-2][2]] = m - abs(r[0][0] - r[1][0]) // 2
	print(*ans)


from bisect import bisect

def crashes(ls, m):
	if len(ls) <= 1:
		return {}
	right = []
	left = []
	ans = {}
	for (x, lr) in ls:
		if lr == 'R':
			right.append(x)
		elif right:
			y = right.pop()
			ans[x] = ans[y] = (x - y) // 2
		else:
			left.append(x)
	for (x, y) in zip(left[::2], left[1::2]):
		ans[x] = ans[y] = (x + y) // 2
	for (x, y) in zip(right[::-2], right[-2::-2]):
		ans[x] = ans[y] = (2 * m - x - y) // 2
	if len(left) % 2 == 1 and len(right) % 2 == 1:
		(x, y) = (left[-1], right[0])
		ans[x] = ans[y] = (2 * m + x - y) // 2
	return ans
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	odd = []
	even = []
	z = list(zip(x, input().split()))
	odd = sorted((zz for zz in z if zz[0] % 2 == 1))
	even = sorted((zz for zz in z if zz[0] % 2 == 0))
	odd_t = crashes(odd, m)
	even_t = crashes(even, m)
	for zz in x:
		d = even_t if zz % 2 == 0 else odd_t
		print(d.get(zz, -1), end=' ')
	print()


from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
input = stdin.readline

def solve():
	pass
t = int(input())
maxN = 101
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = list(map(str, input().split()))
	bots = [(x, dir, i) for (i, (x, dir)) in enumerate(zip(arr, brr))]
	bots.sort()
	even = []
	odd = []
	ans = [-1] * n
	for (x, s, i) in bots:
		if s == 'R':
			if x % 2 == 0:
				even.append((i, x))
			else:
				odd.append((i, x))
		elif x % 2 == 0:
			if even:
				(j, y) = even.pop()
				ans[i] = ans[j] = (x - y) // 2
			else:
				even.append((i, -x))
		elif odd:
			(j, y) = odd.pop()
			ans[i] = ans[j] = (x - y) // 2
		else:
			odd.append((i, -x))
	while len(even) >= 2:
		(i, x) = even.pop()
		(j, y) = even.pop()
		ans[i] = ans[j] = (x - y) // 2 + m - x
	while len(odd) >= 2:
		(i, x) = odd.pop()
		(j, y) = odd.pop()
		ans[i] = ans[j] = (x - y) // 2 + m - x
	print(*ans)


import random
import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
mo = 998244353

def exgcd(a, b):
	if not b:
		return (1, 0)
	(y, x) = exgcd(b, a % b)
	y -= a // b * x
	return (x, y)

def getinv(a, m):
	(x, y) = exgcd(a, m)
	return -1 if x == 1 else x % m

def comb(n, b):
	res = 1
	b = min(b, n - b)
	for i in range(b):
		res = res * (n - i) * getinv(i + 1, mo) % mo
	return res % mo

def quickpower(a, n):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])

def getpref(x):
	if x > 1:
		return x * (x - 1) >> 1
	else:
		return 0

def orafli(upp):
	primes = []
	marked = [False for i in range(upp + 3)]
	prvs = [i for i in range(upp + 3)]
	for i in range(2, upp):
		if not marked[i]:
			primes.append(i)
		for j in primes:
			if i * j >= upp:
				break
			marked[i * j] = True
			prvs[i * j] = j
			if i % j == 0:
				break
	return (primes, prvs)

def lower_ord(c: str) -> int:
	return ord(c) - 97

def upper_ord(c: str) -> int:
	return ord(c) - 65

def read_list():
	return [int(i) for i in input().split()]

def read_int():
	s = input().split()
	if len(s) == 1:
		return int(s[0])
	else:
		return map(int, s)

def ask(s):
	print(f'? {s}', flush=True)

def answer(s):
	print(f'{s}', flush=True)
import functools
import itertools
from fractions import Fraction

def solve():
	(n, m) = read_int()
	li = read_list()
	sc = input().split()
	bots = []
	ans = [-1 for i in range(n)]
	for (k, v, p) in zip(li, sc, range(n)):
		bots.append((k, v, p))
	bots.sort()
	s1 = []
	s2 = []
	rs1 = []
	rs2 = []
	for (k, v, p) in bots:
		if v == 'R':
			if k & 1:
				s1.append((k, v, p))
			else:
				s2.append((k, v, p))
		elif k & 1:
			if s1:
				(kk, vv, pp) = s1.pop()
				ans[p] = ans[pp] = k - kk >> 1
			else:
				rs1.append((k, v, p))
		elif s2:
			(kk, vv, pp) = s2.pop()
			ans[p] = ans[pp] = k - kk >> 1
		else:
			rs2.append((k, v, p))
	rs1.reverse()
	rs2.reverse()
	while len(s1) > 1:
		(k, v, p) = s1.pop()
		(kk, vv, pp) = s1.pop()
		ans[p] = ans[pp] = 2 * m - k - kk >> 1
	while len(s2) > 1:
		(k, v, p) = s2.pop()
		(kk, vv, pp) = s2.pop()
		ans[p] = ans[pp] = 2 * m - k - kk >> 1
	while len(rs1) > 1:
		(k, v, p) = rs1.pop()
		(kk, vv, pp) = rs1.pop()
		ans[p] = ans[pp] = k + kk >> 1
	while len(rs2) > 1:
		(k, v, p) = rs2.pop()
		(kk, vv, pp) = rs2.pop()
		ans[p] = ans[pp] = k + kk >> 1
	s1.reverse()
	s2.reverse()
	rs1.reverse()
	rs2.reverse()
	while s1 and rs1:
		(k, v, p) = s1.pop()
		(kk, vv, pp) = rs1.pop()
		ans[p] = ans[pp] = 2 * m - k + kk >> 1
	while s2 and rs2:
		(k, v, p) = s2.pop()
		(kk, vv, pp) = rs2.pop()
		ans[p] = ans[pp] = 2 * m - k + kk >> 1
	print(*ans)
t = int(input())
for ti in range(t):
	solve()


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=0):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			if mod:
				self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class SegmentTree:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		self.size = n
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, k, x):
		k += self.num
		self.tree[k] = x
		while k > 1:
			self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
			k >>= 1

	def query(self, l, r):
		if r == self.size:
			r = self.num
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += self.num
		r += self.num
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.tree[l] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.tree[r - 1] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		elif Rmin != -1:
			pos = Rmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		else:
			return -1
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import gcd, log
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
for _ in range(int(input())):
	(n, m) = mi()
	X = li()
	D = [d for d in input().split()]
	ans = [-1 for i in range(n)]
	even = []
	odd = []
	for i in range(n):
		if X[i] & 1:
			odd.append((X[i], i))
		else:
			even.append((X[i], i))
	even.sort(key=lambda x: x[0])
	odd.sort(key=lambda x: x[0])
	stack = []
	for (x, idx) in even:
		if D[idx] == 'L':
			if not stack:
				stack.append((-x, idx))
			else:
				(x0, idx0) = stack.pop()
				t = (x - x0) // 2
				ans[idx] = t
				ans[idx0] = t
		else:
			stack.append((x, idx))
	even = stack[::-1]
	stack = []
	for (x, idx) in even:
		if not stack:
			stack.append((2 * m - x, idx))
		else:
			(x0, idx0) = stack.pop()
			t = (x0 - x) // 2
			ans[idx] = t
			ans[idx0] = t
	stack = []
	for (x, idx) in odd:
		if D[idx] == 'L':
			if not stack:
				stack.append((-x, idx))
			else:
				(x0, idx0) = stack.pop()
				t = (x - x0) // 2
				ans[idx] = t
				ans[idx0] = t
		else:
			stack.append((x, idx))
	odd = stack[::-1]
	stack = []
	for (x, idx) in odd:
		if not stack:
			stack.append((2 * m - x, idx))
		else:
			(x0, idx0) = stack.pop()
			t = (x0 - x) // 2
			ans[idx] = t
			ans[idx0] = t
	print(*ans)


t = int(input())

def get(n, m, a):
	stack = [0] * (n + 1)
	top = 0
	res = [-1] * n
	for i in range(n):
		if a[i] > 0:
			top += 1
			stack[top] = i
		elif top == 0 or a[stack[top]] < 0:
			top += 1
			stack[top] = i
		else:
			j = stack[top]
			res[j] = (-a[i] - a[j]) // 2
			res[i] = res[j]
			top -= 1
	if top > 0:
		down = 1
		while top > down and a[stack[down]] < 0 and (a[stack[down + 1]] < 0):
			i = stack[down]
			j = stack[down + 1]
			res[i] = (-a[j] + a[i]) // 2 - a[i]
			res[j] = res[i]
			down += 2
		up = top
		while up > 1 and a[stack[up]] > 0 and (a[stack[up - 1]] > 0):
			i = stack[up - 1]
			j = stack[up]
			res[i] = (a[j] - a[i]) // 2 + (m - a[j])
			res[j] = res[i]
			up -= 2
		if down + 1 == up and down <= top and (up >= 0):
			i = stack[down]
			j = stack[up]
			if -a[i] > m - a[j]:
				res[i] = (-a[i] + a[j]) // 2 + m - a[j]
				res[j] = res[i]
			else:
				res[i] = (a[i] - a[j]) // 2 + m - a[i]
				res[j] = res[i]
	return res
for ts in range(t):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	dir = [i for i in input().split()]
	aa = [(a[i], i) for i in range(n)]
	aa = sorted(aa)
	x1 = []
	p1 = []
	x2 = []
	p2 = []
	for id in range(n):
		i = aa[id][1]
		if a[i] % 2 == 0:
			if dir[i] == 'R':
				x1.append(a[i])
			else:
				x1.append(-a[i])
			p1.append(i)
		else:
			if dir[i] == 'R':
				x2.append(a[i])
			else:
				x2.append(-a[i])
			p2.append(i)
	res1 = get(len(x1), m, x1)
	res2 = get(len(x2), m, x2)
	finRes = [0] * n
	for i in range(len(res1)):
		finRes[p1[i]] = res1[i]
	for i in range(len(res2)):
		finRes[p2[i]] = res2[i]
	for i in finRes:
		print(i, end=' ')
	print()


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	x = list(map(int, input().split()))
	a = input().split()
	z = [-1] * n
	b = []
	c = []
	for i in range(n):
		[b, c][x[i] % 2].append([x[i], a[i], i])
	d = []
	b.sort()
	c.sort()
	b1 = len(b)
	for i in range(b1):
		if d and b[i][1] == 'L' and (d[-1][1] == 'R'):
			z[d[-1][2]] = (b[i][0] - d[-1][0]) // 2
			z[b[i][2]] = (b[i][0] - d[-1][0]) // 2
			d.pop()
		else:
			d.append(b[i])
	e = -1
	for i in d:
		if i[1] == 'R':
			break
		if e == -1:
			e = list(i)
		else:
			z[i[2]] = (i[0] + e[0]) // 2
			z[e[2]] = (i[0] + e[0]) // 2
			e = -1
	f = -1
	for i in d[::-1]:
		if i[1] == 'L':
			break
		if f == -1:
			f = list(i)
		else:
			z[i[2]] = (2 * m - i[0] - f[0]) // 2
			z[f[2]] = (2 * m - i[0] - f[0]) // 2
			f = -1
	if e != -1 and f != -1:
		z[e[2]] = (e[0] + m - f[0] + m) // 2
		z[f[2]] = (e[0] + m - f[0] + m) // 2
	c1 = len(c)
	d = []
	for i in range(c1):
		if d and c[i][1] == 'L' and (d[-1][1] == 'R'):
			z[d[-1][2]] = (c[i][0] - d[-1][0]) // 2
			z[c[i][2]] = (c[i][0] - d[-1][0]) // 2
			d.pop()
		else:
			d.append(c[i])
	e = -1
	for i in d:
		if i[1] == 'R':
			break
		if e == -1:
			e = list(i)
		else:
			z[i[2]] = (i[0] + e[0]) // 2
			z[e[2]] = (i[0] + e[0]) // 2
			e = -1
	f = -1
	for i in d[::-1]:
		if i[1] == 'L':
			break
		if f == -1:
			f = list(i)
		else:
			z[i[2]] = (2 * m - i[0] - f[0]) // 2
			z[f[2]] = (2 * m - i[0] - f[0]) // 2
			f = -1
	if e != -1 and f != -1:
		z[e[2]] = (e[0] + m - f[0] + m) // 2
		z[f[2]] = (e[0] + m - f[0] + m) // 2
	print(*z)


from collections import deque

def solve(n, m, x, d):
	even = []
	odd = []
	for i in range(n):
		if x[i] & 1:
			odd.append((i, x[i], d[i]))
		else:
			even.append((i, x[i], d[i]))
	even_solution = stacksolve(even, m)
	odd_solution = stacksolve(odd, m)
	ans = []
	for i in range(n):
		if i in even_solution:
			ans.append(even_solution[i])
		else:
			ans.append(odd_solution[i])
	return ' '.join(map(str, ans))

def stacksolve(iarr, m):
	rdeque = deque([])
	ldeque = deque([])
	iarr.sort(key=lambda e: e[1])
	ans = {}
	for (i, x, d) in iarr:
		if d == 'R':
			rdeque.append((i, x, d))
		elif len(rdeque) > 0:
			(li, lx, ld) = (i, x, d)
			(ri, rx, rd) = rdeque.pop()
			t = abs(lx - rx) >> 1
			ans[li] = t
			ans[ri] = t
		else:
			ldeque.append((i, x, d))
	while len(ldeque) >= 2:
		(i1, x1, d1) = ldeque.popleft()
		(i2, x2, d2) = ldeque.popleft()
		t = x1 + abs(x2 - x1) // 2
		ans[i1] = t
		ans[i2] = t
	while len(rdeque) >= 2:
		(i1, x1, d1) = rdeque.pop()
		(i2, x2, d2) = rdeque.pop()
		t = m - x1 + abs(x1 - x2) // 2
		ans[i1] = t
		ans[i2] = t
	if len(ldeque) == 1 and len(rdeque) == 1:
		(ir, xr, dr) = rdeque.pop()
		(il, xl, dl) = ldeque.pop()
		(xa, xb) = (xl, m - xr)
		(minx, maxx) = (min(xa, xb), max(xa, xb))
		t = minx + (m + maxx - minx) // 2
		ans[il] = t
		ans[ir] = t
	elif len(ldeque) == 1:
		(i, x, d) = ldeque.pop()
		ans[i] = -1
	elif len(rdeque) == 1:
		(i, x, d) = rdeque.pop()
		ans[i] = -1
	return ans
T = int(input())
for t in range(T):
	(n, m) = tuple(map(int, input().split()))
	x = list(map(int, input().split()))
	d = input().split()
	print(solve(n, m, x, d))


from operator import itemgetter
import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve(n, m, x, s):
	arr = sorted([(i, x[i], s[i]) for i in range(n)], key=itemgetter(1))
	stacks = [[], []]
	ans = [-1] * n
	for (i, xi, si) in arr:
		stk = stacks[xi % 2]
		if not stk:
			stk.append((i, xi, si))
		else:
			(oi, ox, os) = stk[-1]
			if os == b'R' and si == b'L':
				ans[i] = ans[oi] = (xi - ox) // 2
				stk.pop()
			elif os == b'L' and si == b'L':
				ans[i] = ans[oi] = (xi + ox) // 2
				stk.pop()
			else:
				stk.append((i, xi, si))
	for stk in stacks:
		stk.reverse()
		l = len(stk)
		for i in range(0, l, 2):
			if i >= l - 2:
				break
			(ii, xi, _) = stk[i]
			(oi, ox, _) = stk[i + 1]
			ans[ii] = ans[oi] = (2 * m - ox - xi) // 2
		if i == l - 2:
			(ii, xi, si) = stk[i]
			(oi, ox, os) = stk[i + 1]
			if si == b'R' and os == b'R':
				ans[ii] = ans[oi] = (2 * m - ox - xi) // 2
			elif si == b'R' and os == b'L':
				ans[ii] = ans[oi] = (2 * m - xi + ox) // 2
	print(*ans)
T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	s = input().split()
	solve(n, m, x, s)


import sys
input = sys.stdin.readline

def solve(N, M, X, D):
	for i in range(len(X)):
		X[i] = (X[i], D[i], i)
	X.sort()
	ans = [-1 for _ in range(N)]
	prevRight = [[] for _ in range(2)]
	for i in range(len(X)):
		(x, d, idx) = X[i]
		if d == 1:
			prevRight[x % 2].append((idx, x))
		elif prevRight[x % 2]:
			(colliderIdx, colliderPos) = prevRight[x % 2][-1]
			prevRight[x % 2].pop()
			dist = x - colliderPos
			ans[colliderIdx] = dist // 2
			ans[idx] = dist // 2
	prevLeft = [[] for _ in range(2)]
	for i in range(len(X) - 1, -1, -1):
		(x, d, idx) = X[i]
		if ans[idx] != -1:
			continue
		if d == -1:
			prevLeft[x % 2].append((idx, x))
		elif prevLeft[x % 2]:
			(colliderIdx, colliderPos) = prevLeft[x % 2][-1]
			prevLeft[x % 2].pop()
			dist = colliderPos - x
			ans[colliderIdx] = dist // 2
			ans[idx] = dist // 2
	prevLeft = [[] for _ in range(2)]
	for i in range(len(X)):
		(x, d, idx) = X[i]
		if ans[idx] != -1:
			continue
		if d == -1:
			if prevLeft[x % 2]:
				(colliderIdx, colliderPos) = prevLeft[x % 2][-1]
				prevLeft[x % 2].pop()
				dist = x - colliderPos + colliderPos * 2
				ans[colliderIdx] = ans[idx] = dist // 2
			else:
				prevLeft[x % 2].append((idx, x))
	prevRight = [[] for _ in range(2)]
	for i in range(len(X) - 1, -1, -1):
		(x, d, idx) = X[i]
		if ans[idx] != -1:
			continue
		if d == 1:
			if prevRight[x % 2]:
				(colliderIdx, colliderPos) = prevRight[x % 2][-1]
				prevRight[x % 2].pop()
				dist = colliderPos - x + (M - colliderPos) * 2
				ans[colliderIdx] = dist // 2
				ans[idx] = dist // 2
			else:
				prevRight[x % 2].append((idx, x))
	prevLeft = [[] for _ in range(2)]
	for i in range(len(X)):
		(x, d, idx) = X[i]
		if ans[idx] != -1:
			continue
		if d == -1:
			prevLeft[x % 2].append((idx, x))
	for x in prevLeft:
		x.reverse()
	for i in range(len(X) - 1, -1, -1):
		(x, d, idx) = X[i]
		if ans[idx] != -1:
			continue
		if d == 1:
			if prevLeft[x % 2]:
				(colliderIdx, colliderPos) = prevLeft[x % 2][-1]
				prevLeft[x % 2].pop()
				dist = x - colliderPos + colliderPos * 2 + (M - x) * 2
				ans[idx] = ans[colliderIdx] = dist // 2
	print(*ans)
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	X = list(map(int, input().split()))
	D = list(map(lambda x: -1 if x == 'L' else 1, input().split()))
	solve(N, M, X, D)


import io
import os
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappush, heappop, heapify
from math import gcd, inf

def solve(N, M, X, D):
	assert len(X) == N
	assert len(D) == N
	ans = [inf] * N
	order = list(range(N))
	order.sort(key=lambda i: X[i])
	odds = []
	evens = []
	for i in order:
		x = X[i]
		d = D[i]
		if x % 2 == 0:
			stack = evens
		else:
			stack = odds
		if not stack:
			stack.append(i)
		elif D[stack[-1]] == 'R' and d == 'L':
			j = stack.pop()
			dist = X[i] - X[j]
			assert dist % 2 == 0
			ans[i] = dist // 2
			ans[j] = dist // 2
		else:
			stack.append(i)

	def splitLR(arr):
		left = []
		right = []
		for i in arr:
			if D[i] == 'L':
				left.append(i)
			else:
				right.append(i)
		return (left, right)
	(oddL, oddR) = splitLR(odds)
	(evenL, evenR) = splitLR(evens)

	def g(arr, wall):
		if wall == 0:
			wall = 0
			for (i, j) in zip(arr[::2], arr[1::2]):
				t = (X[j] + X[i]) // 2
				assert t >= 1
				ans[i] = t
				ans[j] = t
			if len(arr) % 2:
				return [arr[-1]]
			return []
		else:
			assert wall == M
			arr = arr[::-1]
			for (i, j) in zip(arr[::2], arr[1::2]):
				t = M - (X[j] + X[i]) // 2
				assert t >= 1
				ans[i] = t
				ans[j] = t
			if len(arr) % 2:
				return [arr[-1]]
			return []
	evenL = g(evenL, 0)
	oddL = g(oddL, 0)
	evenR = g(evenR, M)
	oddR = g(oddR, M)

	def h(L, R):
		if not L or not R:
			return
		[l] = L
		[r] = R
		x = X[l]
		y = X[r]
		t = max(x, M - y)
		x = abs(x - t)
		y = y + t if y + t <= M else M - (y + t - M)
		t2 = (y - x) // 2
		assert t2 >= 0
		ans[l] = t + t2
		ans[r] = t + t2
	h(evenL, evenR)
	h(oddL, oddR)
	return ' '.join((str(t) if t != inf else '-1' for t in ans))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, M) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	S = input().decode().split()
	ans = solve(N, M, A, S)
	print(ans)


def gns():
	return list(map(int, input().split()))

def gn():
	return int(input())
t = gn()

def ctime(a, b, m):
	if a[0] > b[0]:
		(a, b) = (b, a)
	if a[1] == b[1]:
		if a[1] == 'L':
			return a[0] + b[0]
		else:
			return 2 * m - a[0] - b[0]
	elif a[1] == 'R':
		return b[0] - a[0]
	else:
		return a[0] + m + m - b[0]

def one_d(ns, ans, m):
	ns.sort(key=lambda x: x[0])
	if len(ns) == 0:
		return
	if len(ns) == 1:
		ans[ns[0][-1]] = -1
		return
	tmp = []
	for i in range(len(ns)):
		if len(tmp) == 0 or ns[i][1] == 'R':
			tmp.append(ns[i])
			continue
		ct = ctime(tmp[-1], ns[i], m)
		ans[tmp[-1][-1]] = ct // 2
		ans[ns[i][-1]] = ct // 2
		tmp.pop()
	while len(tmp) > 1:
		ct = ctime(tmp[-1], tmp[-2], m)
		ans[tmp[-1][-1]] = ct // 2
		ans[tmp[-2][-1]] = ct // 2
		tmp.pop()
		tmp.pop()
	if len(tmp) == 1:
		ans[tmp[0][-1]] = -1

def one():
	(n, m) = gns()
	ns = gns()
	ds = list(input().split())
	ans = [-2] * n
	odd = []
	evn = []
	for i in range(n):
		if ns[i] % 2 == 0:
			evn.append((ns[i], ds[i], i))
		else:
			odd.append((ns[i], ds[i], i))
	one_d(odd, ans, m)
	one_d(evn, ans, m)
	return ' '.join(map(str, ans))
for i in range(t):
	print(one())


import sys

def task_c():
	input = sys.stdin.readline
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		pos = list(map(int, input().split()))
		dir = list(map(str, input().split()))
		robots = [(pos[i], 1 if dir[i] == 'R' else -1, i) for i in range(n)]
		ans = [-1] * n

		def solve(v):
			v.sort(key=lambda x: x[0])
			stk = []
			for (x, dir, id) in v:
				if dir == -1:
					if stk:
						(x2, dir2, id2) = stk.pop()
						if dir2 == 1:
							ans[id] = ans[id2] = (x - x2) // 2
						else:
							ans[id] = ans[id2] = (x + x2) // 2
					else:
						stk.append((x, dir, id))
				else:
					stk.append((x, dir, id))
			while len(stk) >= 2:
				(x, dir, id) = stk.pop()
				(x2, dir2, id2) = stk.pop()
				if dir2 == 1:
					ans[id] = ans[id2] = (2 * m - x - x2) // 2
				else:
					ans[id] = ans[id2] = (2 * m - x + x2) // 2
		solve([r for r in robots if r[0] % 2 == 0])
		solve([r for r in robots if r[0] % 2 == 1])
		print(*ans)
task_c()


from collections import deque

def solve(n, m, xarr, darr):
	oddarr = []
	evenarr = []
	for i in range(n):
		if xarr[i] & 1:
			oddarr.append((xarr[i], darr[i], i))
		else:
			evenarr.append((xarr[i], darr[i], i))
	ans = [-1] * n
	rodd = partsolve(oddarr, m)
	for k in rodd:
		ans[k] = rodd[k]
	reven = partsolve(evenarr, m)
	for k in reven:
		ans[k] = reven[k]
	return ' '.join(map(str, ans))

def partsolve(arr, m):
	res = {}
	arr.sort(key=lambda e: e[0])
	(Ldeq, Rdeq) = (deque([]), deque([]))
	for (x, d, i) in arr:
		if d == 'L':
			Ldeq.append((x, d, i))
		else:
			Rdeq.append((x, d, i))
		if Ldeq and Rdeq and (Ldeq[-1][0] > Rdeq[-1][0]):
			(lx, ld, li) = Ldeq.pop()
			(rx, rd, ri) = Rdeq.pop()
			tm = lx - rx >> 1
			res[li] = tm
			res[ri] = tm
	while len(Ldeq) > 1:
		(x1, d1, i1) = Ldeq.popleft()
		(x2, d2, i2) = Ldeq.popleft()
		tm = x1 + (x2 - x1 >> 1)
		res[i1] = tm
		res[i2] = tm
	while len(Rdeq) > 1:
		(x1, d1, i1) = Rdeq.pop()
		(x2, d2, i2) = Rdeq.pop()
		tm = m - x1 + (x1 - x2 >> 1)
		res[i1] = tm
		res[i2] = tm
	if Ldeq and Rdeq:
		(xl, dl, il) = Ldeq.popleft()
		(xr, dr, ir) = Rdeq.pop()
		(a, b) = (xl, m - xr)
		if b < a:
			(a, b) = (b, a)
		tm = m + a + b >> 1
		res[il] = tm
		res[ir] = tm
	return res
T = int(input())
for t in range(T):
	(n, m) = tuple(map(int, input().split()))
	xarr = list(map(int, input().split()))
	darr = input().split()
	print(solve(n, m, xarr, darr))


import math
import sys
from bisect import *

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve(N, M, pos, dirs):
	can = {'R': [], 'L_odd': [], 'L_even': []}
	for i in range(N):
		if dirs[i] == 'R':
			can[dirs[i]].append((pos[i], i))
		elif pos[i] & 1:
			can['L_odd'].append((pos[i], i))
		else:
			can['L_even'].append((pos[i], i))
	ans = [-1] * N
	for key in can:
		can[key].sort()
	next_L = {'odd': [], 'even': []}
	while can['R']:
		(r, r_idx) = can['R'].pop()
		if r & 1:
			key = 'L_odd'
		else:
			key = 'L_even'
		idx = bisect_left(can[key], (r, r_idx))
		if 0 <= idx < len(can[key]) and can[key][idx][0] > r:
			(l, l_idx) = can[key].pop(idx)
			ans[r_idx] = (l + r) // 2 - r
			ans[l_idx] = (l + r) // 2 - r
		elif r & 1:
			next_L['odd'].append((r, r_idx))
		else:
			next_L['even'].append((r, r_idx))
	next_next_L = {'odd': [], 'even': []}
	for key in ['odd', 'even']:
		for i in range(0, len(next_L[key]), 2):
			if i + 1 < len(next_L[key]):
				(v1, idx1) = next_L[key][i]
				(v2, idx2) = next_L[key][i + 1]
				time = abs(v1 - v2) // 2 + M - v1
				ans[idx1] = time
				ans[idx2] = time
			else:
				next_next_L[key].append(next_L[key][i])
	next_next_R = {'odd': [], 'even': []}
	for key in ['L_odd', 'L_even']:
		for i in range(0, len(can[key]), 2):
			if i + 1 < len(can[key]):
				(v1, idx1) = can[key][i]
				(v2, idx2) = can[key][i + 1]
				time = abs(v1 - v2) // 2 + v1
				ans[idx1] = time
				ans[idx2] = time
			else:
				next_next_R[key[2:]].append(can[key][i])
	for key in ['odd', 'even']:
		(L_idx, R_idx) = (len(next_next_L[key]) - 1, 0)
		while L_idx >= 0 and R_idx < len(next_next_R[key]):
			(l, l_idx) = next_next_L[key][L_idx]
			(r, r_idx) = next_next_R[key][R_idx]
			time = (M * 2 - (l - r)) // 2
			ans[l_idx] = time
			ans[r_idx] = time
			L_idx -= 1
			R_idx += 1
	return ' '.join(map(str, ans))
T = int(input())
for _ in range(T):
	(N, M) = get_ints()
	pos = get_ints()
	dirs = input().split()
	print(solve(N, M, pos, dirs))


import sys
from collections import *
input = sys.stdin.readline
cas = int(input())
while cas:
	cas -= 1
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	d = list(map(str, input().split()))
	ans = [-1 for i in range(n + 1)]
	g = []
	for i in range(n):
		g.append([x[i], d[i], i])
	g.sort()
	odd = deque([])
	even = deque([])
	for tmp in g:
		if tmp[0] % 2:
			if tmp[1] == 'L' and odd:
				last = odd.pop()
				if last[1] == 'L':
					odd.append(last)
					odd.append(tmp)
				else:
					time = (tmp[0] - last[0]) // 2
					ans[tmp[2]] = time
					ans[last[2]] = time
			else:
				odd.append(tmp)
		elif tmp[1] == 'L' and even:
			last = even.pop()
			if last[1] == 'L':
				even.append(last)
				even.append(tmp)
			else:
				time = (tmp[0] - last[0]) // 2
				ans[tmp[2]] = time
				ans[last[2]] = time
		else:
			even.append(tmp)
	while odd:
		pre = odd.popleft()
		if pre[1] == 'R':
			odd.appendleft(pre)
			break
		if odd:
			now = odd.popleft()
			if now[1] == 'L':
				time = (now[0] + pre[0]) // 2
				ans[now[2]] = time
				ans[pre[2]] = time
			else:
				odd.appendleft(now)
				odd.appendleft(pre)
				break
		else:
			odd.appendleft(pre)
			break
	while odd:
		pre = odd.pop()
		if pre[1] == 'L':
			odd.append(pre)
			break
		if odd:
			now = odd.pop()
			if now[1] == 'R':
				time = (2 * m - now[0] - pre[0]) // 2
				ans[now[2]] = time
				ans[pre[2]] = time
			else:
				odd.append(now)
				odd.append(pre)
				break
		else:
			odd.append(pre)
			break
	if len(odd) == 2:
		r = odd.pop()
		l = odd.pop()
		time = (2 * m - r[0] + l[0]) // 2
		ans[l[2]] = time
		ans[r[2]] = time
	while even:
		pre = even.popleft()
		if pre[1] == 'R':
			even.appendleft(pre)
			break
		if even:
			now = even.popleft()
			if now[1] == 'L':
				time = (now[0] + pre[0]) // 2
				ans[now[2]] = time
				ans[pre[2]] = time
			else:
				even.appendleft(now)
				even.appendleft(pre)
				break
		else:
			even.appendleft(pre)
			break
	while even:
		pre = even.pop()
		if pre[1] == 'L':
			even.append(pre)
			break
		if even:
			now = even.pop()
			if now[1] == 'R':
				time = (2 * m - now[0] - pre[0]) // 2
				ans[now[2]] = time
				ans[pre[2]] = time
			else:
				even.append(now)
				even.append(pre)
				break
		else:
			even.append(pre)
			break
	if len(even) == 2:
		r = even.pop()
		l = even.pop()
		time = (2 * m - r[0] + l[0]) // 2
		ans[l[2]] = time
		ans[r[2]] = time
	for i in range(n):
		if i == n - 1:
			print(ans[i])
		else:
			print(ans[i], end=' ')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve(robots, directions, wall):
	(even, odd, res) = ([], [], [-1] * len(robots))
	for (i, r, d) in zip(range(len(robots)), robots, directions):
		if r % 2 == 1:
			odd += [(r, i, d)]
		else:
			even += [(r, i, d)]
	odd.sort(key=lambda x: x[0])
	even.sort(key=lambda x: x[0])

	def helper(arr):
		(tmp, size) = ([], len(arr))
		for i in range(size):
			(robot, idx, di) = arr[i]
			if di == 'L':
				if tmp:
					(robot0, idx0) = tmp.pop()
					res[idx] = res[idx0] = abs(robot - robot0) // 2
				else:
					tmp += [(-robot, idx)]
			else:
				tmp += [(robot, idx)]
		while len(tmp) > 1:
			(robot1, idx1) = tmp.pop()
			robot1 = wall + (wall - robot1)
			(robot0, idx0) = tmp.pop()
			res[idx0] = res[idx1] = abs(robot1 - robot0) // 2
	helper(odd)
	helper(even)
	print(*res)
for _ in range(int(input())):
	(_, wall) = map(int, input().split())
	robots = list(map(int, input().split()))
	directions = list(input().split())
	solve(robots, directions, wall)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	d = [x for x in input().split()]
	(a1, a2) = ([], [])
	for i in range(n):
		if a[i] % 2 == 0:
			a2.append(i)
		else:
			a1.append(i)
	ans = [-1 for i in range(n)]
	a1 = sorted(a1, key=lambda x: a[x])
	a2 = sorted(a2, key=lambda x: a[x])
	(s1, s2) = ([], [])
	for i in a2:
		if d[i] == 'R':
			s1.append(i)
		elif not s1:
			s2.append(i)
		else:
			k = s1.pop()
			ans[i] = ans[k] = (a[i] - a[k]) // 2
	while len(s1) > 1:
		x1 = s1.pop()
		x2 = s1.pop()
		ans[x1] = ans[x2] = (a[x1] - a[x2]) // 2 + (m - a[x1])
	z = 0
	while z < len(s2) - 1:
		x1 = s2[z + 1]
		x2 = s2[z]
		ans[x1] = ans[x2] = (a[x1] - a[x2]) // 2 + a[x2]
		z += 2
	if len(s1) % 2 == 1 and len(s2) % 2 == 1:
		k1 = s1.pop()
		k2 = s2[-1]
		if m - a[k1] > a[k2]:
			x1 = m - a[k1]
			x2 = a[k2]
		else:
			x1 = a[k2]
			x2 = m - a[k1]
		ans[k1] = ans[k2] = x1 + (m - x1 + x2) // 2
	(s1, s2) = ([], [])
	for i in a1:
		if d[i] == 'R':
			s1.append(i)
		elif not s1:
			s2.append(i)
		else:
			k = s1.pop()
			ans[i] = ans[k] = (a[i] - a[k]) // 2
	while len(s1) > 1:
		x1 = s1.pop()
		x2 = s1.pop()
		ans[x1] = ans[x2] = (a[x1] - a[x2]) // 2 + (m - a[x1])
	z = 0
	while z < len(s2) - 1:
		x1 = s2[z + 1]
		x2 = s2[z]
		ans[x1] = ans[x2] = (a[x1] - a[x2]) // 2 + a[x2]
		z += 2
	if len(s1) % 2 == 1 and len(s2) % 2 == 1:
		k1 = s1.pop()
		k2 = s2[-1]
		if m - a[k1] > a[k2]:
			x1 = m - a[k1]
			x2 = a[k2]
		else:
			x1 = a[k2]
			x2 = m - a[k1]
		ans[k1] = ans[k2] = x1 + (m - x1 + x2) // 2
	for i in ans:
		print(i, end=' ')
	print()


from sys import stdin, stdout
import math, bisect, heapq
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	print(' '.join(list(map(str, a))))

def solve():
	(n, m) = L()
	a = L()
	b = C()
	c = [(a[i], b[i], i) for i in range(n)]
	c.sort()
	(odd, even) = ([], [])
	ans = [-1] * n
	for i in range(n):
		(x, y, z) = c[i]
		if y == 'R':
			if x % 2:
				odd += [(z, x)]
			else:
				even += [(z, x)]
		elif x % 2:
			if odd:
				temp = odd.pop()
				p = (x - temp[1]) // 2
				ans[z] = ans[temp[0]] = p
			else:
				odd += [(z, -x)]
		elif even:
			temp = even.pop()
			p = (x - temp[1]) // 2
			ans[z] = ans[temp[0]] = p
		else:
			even += [(z, -x)]
	while len(even) >= 2:
		p = even.pop()
		q = even.pop()
		ans[p[0]] = ans[q[0]] = (p[1] - q[1]) // 2 + (m - p[1])
	even = odd
	while len(even) >= 2:
		p = even.pop()
		q = even.pop()
		ans[p[0]] = ans[q[0]] = (p[1] - q[1]) // 2 + (m - p[1])
	pr(ans)
for _ in range(I()):
	solve()


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
MOD = 1000000007

def si():
	return input()

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())

def sout(v):
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def linear_sieve(n):
	primes = []
	least_prime_divs = [0] * (n + 1)
	for i in range(2, n + 1):
		if not least_prime_divs[i]:
			least_prime_divs[i] = i
			primes.append(i)
		for p in primes:
			if i * p > n or p > least_prime_divs[i]:
				break
			least_prime_divs[i * p] = p
	return (primes, least_prime_divs)

def helper(eve, a, ans, m):
	st = []
	left = []
	for i in eve:
		if a[i][1] == 'R':
			st.append(i)
		elif len(st) and a[i][1] == 'L':
			c = st.pop()
			ans[a[c][0]] = (a[i][0] - a[c][0]) // 2
			ans[a[i][0]] = ans[a[c][0]]
		else:
			left.append(i)
	rem = 0
	if len(st) and len(st) % 2 == 0:
		for i in range(0, len(st), 2):
			ans[a[st[i]][0]] = (a[st[i + 1]][0] - a[st[i]][0]) // 2 + (m - a[st[i + 1]][0])
			ans[a[st[i + 1]][0]] = ans[a[st[i]][0]]
	elif len(st) % 2 == 1:
		rem += 1
		for i in range(1, len(st), 2):
			ans[a[st[i]][0]] = (a[st[i + 1]][0] - a[st[i]][0]) // 2 + (m - a[st[i + 1]][0])
			ans[a[st[i + 1]][0]] = ans[a[st[i]][0]]
	if len(left) and len(left) % 2 == 0:
		for i in range(0, len(left), 2):
			ans[a[left[i]][0]] = (a[left[i + 1]][0] - a[left[i]][0]) // 2 + a[left[i]][0]
			ans[a[left[i + 1]][0]] = ans[a[left[i]][0]]
	if len(left) % 2 == 1:
		rem += 1
		for i in range(0, len(left) - 1, 2):
			ans[a[left[i]][0]] = (a[left[i + 1]][0] - a[left[i]][0]) // 2 + a[left[i]][0]
			ans[a[left[i + 1]][0]] = ans[a[left[i]][0]]
	if rem == 2:
		ans[a[st[0]][0]] = m - (a[st[0]][0] - a[left[-1]][0]) // 2
		ans[a[left[-1]][0]] = ans[a[st[0]][0]]
	return ans
t = ii()
while t:
	t -= 1
	(n, m) = mi()
	c = li()
	a = []
	for i in c:
		a.append(i)
	b = si()
	j = 0
	for i in range(n):
		a[i] = [a[i], b[j]]
		j += 2
	a.sort(key=lambda x: x[0])
	ans = {}
	for i in c:
		ans[i] = -1
	eve = []
	odd = []
	for i in range(n):
		if a[i][0] % 2 == 0:
			eve.append(i)
		else:
			odd.append(i)
	ans = helper(eve, a, ans, m)
	ans = helper(odd, a, ans, m)
	for i in c:
		print(ans[i], end=' ')
	print()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(zip(map(int, input().split()), input().split()))
	r = [[], []]
	for i in range(n):
		j = arr[i][0] % 2
		r[j].append((arr[i][0], arr[i][1], i))
	(odd, even) = (r[1], r[0])
	time = [-1] * n
	s = []
	for (c, d, idx) in sorted(odd):
		if d == 'R':
			s.append((idx, c))
		elif s == []:
			s.append((idx, -c))
		else:
			(tidx, tc) = s.pop()
			time[idx] = (c - tc) // 2
			time[tidx] = time[idx]
	while len(s) > 1:
		(idx1, c1) = s.pop()
		(idx2, c2) = s.pop()
		time[idx1] = (2 * m - c1 - c2) // 2
		time[idx2] = time[idx1]
	s = []
	for (c, d, idx) in sorted(even):
		if d == 'R':
			s.append((idx, c))
		elif s == []:
			s.append((idx, -c))
		else:
			(tidx, tc) = s.pop()
			time[idx] = (c - tc) // 2
			time[tidx] = time[idx]
	while len(s) > 1:
		(idx1, c1) = s.pop()
		(idx2, c2) = s.pop()
		time[idx1] = (2 * m - c1 - c2) // 2
		time[idx2] = time[idx1]
	print(' '.join(map(str, time)))


import sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
from math import *
tc = 1
tc = int(input())
for test in range(1, tc + 1):
	(n, m) = inp()
	a = inp()
	b = list(map(str, input().split()))
	odd = []
	even = []
	for i in range(n):
		if a[i] & 1:
			odd.append([a[i], b[i], i])
		else:
			even.append([a[i], b[i], i])
	ans = [-1] * n

	def solve(arr):
		arr.sort()
		stack = []
		for i in range(len(arr)):
			if stack and stack[-1][1] != arr[i][1]:
				res = (arr[i][0] - stack[-1][0]) // 2
				ans[arr[i][2]] = ans[stack[-1][2]] = res
				stack.pop()
			elif arr[i][1] == 'L':
				stack.append([-arr[i][0], 'R', arr[i][2]])
			else:
				stack.append([arr[i][0], arr[i][1], arr[i][2]])
		brr = []
		for i in range(len(stack) - 1, -1, -1):
			if brr:
				res = (brr[-1][0] - stack[i][0]) // 2
				ans[brr[-1][2]] = ans[stack[i][2]] = res
				brr.pop()
			else:
				brr.append([stack[i][0] + 2 * (m - stack[i][0]), 'L', stack[i][2]])
		return
	solve(odd)
	solve(even)
	print(*ans)


import sys
import math
imp = 'IMPOSSIBLE'
t = int(input())
for test in range(t):
	(n, m) = list(map(int, input().split(' ')))
	xx = list(map(int, input().split(' ')))
	sorx = sorted(enumerate(xx), key=lambda z: z[1])
	porx = [i[0] for i in sorx]
	invpor = [i[0] for i in sorted(enumerate(porx), key=lambda z: z[1])]
	x = [i[1] for i in sorx]
	res = ['' for i in range(n)]
	ss = input().split(' ')
	if test != t - 1:
		ss[-1] = ss[-1][0]
	s = [ss[i[0]] for i in sorx]
	lastl1 = -1
	lastl2 = -1
	pairs = []
	r1 = []
	r2 = []
	for i in range(n):
		if x[i] % 2 == 1:
			if s[i] == 'L':
				if r1:
					rr = r1.pop()
					pairs.append([rr, i])
				elif lastl1 == -1:
					lastl1 = i
				else:
					pairs.append([lastl1, i])
					lastl1 = -1
			else:
				r1.append(i)
		elif s[i] == 'L':
			if r2:
				rr = r2.pop()
				pairs.append([rr, i])
			elif lastl2 == -1:
				lastl2 = i
			else:
				pairs.append([lastl2, i])
				lastl2 = -1
		else:
			r2.append(i)
	lastr1 = -1
	lastr2 = -1
	while r1:
		if lastr1 == -1:
			lastr1 = r1.pop()
		else:
			rr = r1.pop()
			pairs.append([lastr1, rr])
			lastr1 = -1
	while r2:
		if lastr2 == -1:
			lastr2 = r2.pop()
		else:
			rr = r2.pop()
			pairs.append([lastr2, rr])
			lastr2 = -1
	if lastr1 > -1 and lastl1 > -1:
		pairs.append([lastl1, lastr1])
		lastl1 = -1
		lastr1 = -1
	elif lastl1 > -1:
		res[lastl1] = '-1'
	elif lastr1 > -1:
		res[lastr1] = '-1'
	if lastr2 > -1 and lastl2 > -1:
		pairs.append([lastl2, lastr2])
		lastl2 = -1
		lastr2 = -1
	elif lastl2 > -1:
		res[lastl2] = '-1'
	elif lastr2 > -1:
		res[lastr2] = '-1'
	for pair in pairs:
		if s[pair[0]] == 'L':
			if s[pair[1]] == 'L':
				res[pair[0]] = str((x[pair[0]] + x[pair[1]]) // 2)
				res[pair[1]] = str((x[pair[0]] + x[pair[1]]) // 2)
			elif x[pair[0]] > x[pair[1]]:
				res[pair[0]] = str((x[pair[0]] - x[pair[1]]) // 2)
				res[pair[1]] = str((x[pair[0]] - x[pair[1]]) // 2)
			else:
				res[pair[0]] = str((x[pair[0]] + 2 * m - x[pair[1]]) // 2)
				res[pair[1]] = str((x[pair[0]] + 2 * m - x[pair[1]]) // 2)
		elif s[pair[1]] == 'R':
			res[pair[0]] = str((2 * m - x[pair[0]] - x[pair[1]]) // 2)
			res[pair[1]] = str((2 * m - x[pair[0]] - x[pair[1]]) // 2)
		elif x[pair[0]] < x[pair[1]]:
			res[pair[0]] = str((x[pair[1]] - x[pair[0]]) // 2)
			res[pair[1]] = str((x[pair[1]] - x[pair[0]]) // 2)
		else:
			res[pair[0]] = str((x[pair[1]] + 2 * m - x[pair[0]]) // 2)
			res[pair[1]] = str((x[pair[1]] + 2 * m - x[pair[0]]) // 2)
	resres = [res[i] for i in invpor]
	print(' '.join(resres))


from collections import deque

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, m) = readIntArr()
		xes = readIntArr()
		direction = input().split()
		ans = [-1] * n

		def solve(xdi):
			xdi.sort()
			rightDeque = deque([])
			for (x, d, i) in xdi:
				if d == 'L':
					if rightDeque:
						(xr, ir) = rightDeque.pop()
						time = (x - xr) // 2
						ans[i] = ans[ir] = time
					else:
						rightDeque.appendleft([-x, i])
				else:
					rightDeque.append([x, i])
			while len(rightDeque) >= 2:
				(xl, il) = rightDeque.pop()
				xl = m + (m - xl)
				(xr, ir) = rightDeque.pop()
				time = (xl - xr) // 2
				ans[il] = ans[ir] = time
		evenxdi = []
		oddxdi = []
		for i in range(n):
			if xes[i] % 2 == 0:
				evenxdi.append([xes[i], direction[i], i])
			else:
				oddxdi.append([xes[i], direction[i], i])
		solve(evenxdi)
		solve(oddxdi)
		allans.append(ans)
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(i, j):
	print('? {} {}'.format(i, j))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(' '.join([str(x) for x in ans])))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


import os, sys, time, collections as c, math, pprint as p, itertools as it, operator as op, bisect as bs, functools as fn
(maxx, localsys, mod) = (float('inf'), 0, int(1000000000.0 + 7))
(nCr, ceil) = (lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r), lambda n, x: (n + x - 1) // x)
(osi, oso) = ('/home/priyanshu/Documents/sublimetextproject/input.txt', '/home/priyanshu/Documents/sublimetextproject/output.txt')
if os.path.exists(osi):
	sys.stdin = open(osi, 'r')
	sys.stdout = open(oso, 'w')
from fractions import Fraction
input = sys.stdin.readline

def maps():
	return map(int, input().split())

def solve(arr, m, ans):
	st = []
	arr.sort()
	for (x, dir, idx) in arr:
		if dir == 'L':
			if not st:
				st.append((idx, -x))
			else:
				(i2, x2) = st.pop()
				ans[idx] = ans[i2] = (x - x2) // 2
		else:
			st.append((idx, x))
	while len(st) >= 2:
		(i1, x1) = st.pop()
		x1 = m + (m - x1)
		(i2, x2) = st.pop()
		ans[i1] = ans[i2] = (x1 - x2) // 2
for _ in range(int(input())):
	(n, m) = maps()
	info = [*zip(list(maps()), list(input().split()))]
	(I, ans) = ([[], []], [-1] * n)
	for idx in range(n):
		(x, dir) = info[idx]
		I[x & 1].append((x, dir, idx))
	solve(I[0], m, ans)
	solve(I[1], m, ans)
	print(*ans)


def partners(robots):
	robots.sort()
	partnerships = []
	stack = []
	for robot in robots:
		if len(stack) == 0 or robot[1] == 'R':
			stack.append(robot)
		else:
			poppedRobot = stack.pop()
			partnerships.append((poppedRobot, robot))
	while len(stack) > 1:
		poppedRobot1 = stack.pop()
		poppedRobot2 = stack.pop()
		partnerships.append((poppedRobot2, poppedRobot1))
	return partnerships
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	coords = list(map(int, input().split()))
	direction = list(input().split())
	robots = list(zip(coords, direction, range(n)))
	odds = []
	evens = []
	for robot in robots:
		if robot[0] % 2 == 0:
			evens.append(robot)
		else:
			odds.append(robot)
	partnerships = partners(odds) + partners(evens)
	distances = [-1] * n
	for (a, b) in partnerships:
		if a[1] == 'R' and b[1] == 'L':
			distance = (b[0] - a[0]) // 2
		elif a[1] == 'L' and b[1] == 'L':
			distance = (b[0] + a[0]) // 2
		elif a[1] == 'R' and b[1] == 'R':
			distance = (2 * m - a[0] - b[0]) // 2
		else:
			distance = (2 * m + a[0] - b[0]) // 2
		distances[a[2]] = distance
		distances[b[2]] = distance
	print(*distances)


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.readline

	def solve(info, ans, M):
		st = []
		N = len(info)
		for i in range(N):
			(x, j, d) = info[i]
			if d == 'L':
				if st:
					(x0, j0) = st.pop()
					ans[j] = ans[j0] = abs(x - x0) // 2
				else:
					st.append((-x, j))
			else:
				st.append((x, j))
		while len(st) > 1:
			(x1, j1) = st.pop()
			x1 = M + (M - x1)
			(x0, j0) = st.pop()
			ans[j0] = ans[j1] = abs(x1 - x0) // 2
	for _ in range(int(input())):
		(N, M) = map(int, input().split())
		X = list(map(int, input().split()))
		LR = list(input().split())
		even = []
		odd = []
		for (i, x) in enumerate(X):
			if x & 1:
				odd.append((x, i, LR[i]))
			else:
				even.append((x, i, LR[i]))
		odd.sort(key=lambda y: y[0])
		even.sort(key=lambda y: y[0])
		ans = [-1] * N
		solve(odd, ans, M)
		solve(even, ans, M)
		print(*ans)
main()


from collections import deque
import sys

def main(N, M, X, S):
	ans = [-1] * N
	O = []
	E = []
	for (i, (x, s)) in enumerate(zip(X, S)):
		if x & 1:
			O.append(i)
		else:
			E.append(i)

	def f(I):
		L = deque()
		R = []
		I.sort(key=lambda i: X[i])
		for i in I:
			(x, s) = (X[i], S[i])
			if s == 'R':
				R.append(i)
			elif R:
				j = R.pop()
				xj = X[j]
				t = (x - xj) // 2
				ans[i] = t
				ans[j] = t
			else:
				L.append(i)
		while len(L) >= 2:
			i = L.popleft()
			j = L.popleft()
			(a, b) = (X[i], X[j])
			t = a + (b - a) // 2
			ans[i] = t
			ans[j] = t
		while len(R) >= 2:
			j = R.pop()
			i = R.pop()
			(a, b) = (X[i], X[j])
			t = M - (a + b) // 2
			ans[i] = t
			ans[j] = t
		if L and R:
			i = L.pop()
			j = R.pop()
			(a, b) = (X[i], X[j])
			t = M + (a - b) // 2
			ans[i] = t
			ans[j] = t
	f(O)
	f(E)
	print(*ans)
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	(*X,) = map(int, input().split())
	S = input().rstrip().split()
	main(N, M, X, S)


from collections import deque

class Robot:

	def __init__(self, number, pos, direct):
		self.pos = pos
		self.dir = direct
		self.number = number

def Print_robots(robots):
	for robot in robots:
		print(robot.pos, end=' ')
	print()
t = int(input())
for test in range(t):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	direct = list(input().split())
	robots = []
	for i in range(n):
		robots.append(Robot(i, x[i], direct[i]))
	robots.sort(key=lambda robot: robot.pos)
	ans = [-1 for i in range(n)]
	for p in range(2):
		stack = deque()
		for robot in robots:
			if robot.pos % 2 != p:
				continue
			if robot.dir == 'L':
				if not stack:
					robot.pos = -robot.pos
					robot.dir == 'R'
					stack.append(robot)
				else:
					left_robot = stack.pop()
					ans[robot.number] = ans[left_robot.number] = (robot.pos - left_robot.pos) // 2
			else:
				stack.append(robot)
		while stack:
			right_robot = stack.pop()
			right_robot.pos = m + m - right_robot.pos
			if stack:
				left_robot = stack.pop()
			else:
				ans[right_robot.number] = -1
				break
			ans[right_robot.number] = ans[left_robot.number] = (right_robot.pos - left_robot.pos) // 2
	for i in range(n):
		print(ans[i], end=' ')


for cs in range(int(input())):
	(n, m) = map(int, input().split())
	X = list(map(int, input().split()))
	D = list(map(str, input().split()))
	X_odd = []
	X_even = []
	ans = [-1 for _ in range(n)]
	for i in range(n):
		if X[i] % 2 == 1:
			X_odd.append([X[i], D[i], i])
		else:
			X_even.append([X[i], D[i], i])
	X_odd.sort()
	X_even.sort()

	def F(Y):
		stack = []
		for r in Y:
			if len(stack) == 0:
				stack.append(r)
			elif r[1] == 'L':
				if stack[-1][1] == 'L':
					x = (r[0] + stack[-1][0]) // 2
					ans[r[2]] = x
					ans[stack[-1][2]] = x
					stack.pop()
				elif stack[-1][1] == 'R':
					ans[r[2]] = (r[0] - stack[-1][0]) // 2
					ans[stack[-1][2]] = ans[r[2]]
					stack.pop()
			else:
				stack.append(r)
		while len(stack) > 1:
			f = stack[-1]
			stack.pop()
			s = stack[-1]
			stack.pop()
			if f[1] == 'R' and s[1] == 'R':
				ans[f[2]] = ans[s[2]] = (2 * m - f[0] - s[0]) // 2
			elif f[1] == 'R' and s[1] == 'L':
				ans[f[2]] = ans[s[2]] = (m - f[0] + s[0] + m) // 2
	F(X_odd)
	F(X_even)
	print(*ans)


def partner(robots):
	robots.sort()
	partnerships = []
	stack = []
	for robot in robots:
		if len(stack) == 0 or robot[1] == 'R':
			stack.append(robot)
		else:
			poppedRobot = stack.pop()
			partnerships.append((poppedRobot, robot))
	while len(stack) > 1:
		poppedRobot1 = stack.pop()
		poppedRobot2 = stack.pop()
		partnerships.append((poppedRobot2, poppedRobot1))
	return partnerships
NoOfTestCases = int(input())
for t in range(NoOfTestCases):
	(n, m) = [int(i) for i in input().strip().split(' ')]
	co_ordinates = [int(x) for x in input().strip().split(' ')]
	directions = [x for x in input().split(' ')]
	robots = list(zip(co_ordinates, directions, range(n)))
	odd = []
	even = []
	for robot in robots:
		if robot[0] % 2 == 0:
			even.append(robot)
		else:
			odd.append(robot)
	partnerships = partner(even) + partner(odd)
	distances = [-1] * n
	for (a, b) in partnerships:
		if a[1] == 'R' and b[1] == 'L':
			distance = (b[0] - a[0]) // 2
		elif a[1] == 'L' and b[1] == 'L':
			distance = (b[0] + a[0]) // 2
		elif a[1] == 'R' and b[1] == 'R':
			distance = (2 * m - (a[0] + b[0])) // 2
		else:
			distance = (2 * m + a[0] - b[0]) // 2
		distances[a[2]] = distance
		distances[b[2]] = distance
	print(*distances)


def binarysearch(x, l):
	low = 0
	high = len(l) - 1
	ans = high + 1
	while low <= high:
		mid = (low + high) // 2
		if l[mid][0] < x:
			low = mid + 1
		else:
			ans = mid
			high = mid - 1
	return ans
t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	u = []
	v = []
	p = {i: -1 for i in range(n)}
	a = list(map(int, input().split(' ')))
	b = input().split(' ')
	for i in range(n):
		if a[i] % 2:
			u.append([a[i], b[i], i])
		else:
			v.append([a[i], b[i], i])
	d = [u, v]
	u.sort(key=lambda x: x[0])
	v.sort(key=lambda x: x[0])
	for listi in d:
		rl = []
		ll = []
		for i in range(len(listi)):
			if listi[i][1] == 'R':
				rl.append([listi[i][0], listi[i][2]])
			else:
				ll.append([listi[i][0], listi[i][2]])
		ppp = len(rl)
		for j in reversed(range(ppp)):
			ans = binarysearch(rl[j][0], ll)
			if ans < len(ll):
				p[rl[j][1]] = (ll[ans][0] - rl[j][0]) / 2
				p[ll[ans][1]] = p[rl[j][1]]
				ll.pop(ans)
				rl.pop(j)
		kk = len(rl)
		for pp in range(kk - 1, 0, -2):
			p[rl[pp][1]] = m - (rl[pp][0] + rl[pp - 1][0]) / 2
			p[rl[pp - 1][1]] = p[rl[pp][1]]
			rl.pop()
			rl.pop()
		lll = len(ll)
		for pp in range(0, lll - 1, 2):
			p[ll[pp][1]] = (ll[pp + 1][0] + ll[pp][0]) / 2
			p[ll[pp + 1][1]] = p[ll[pp][1]]
		if ll and p[ll[-1][1]] == -1 and rl:
			p[ll[-1][1]] = (ll[-1][0] - rl[0][0]) / 2 + m
			p[rl[0][1]] = p[ll[-1][1]]
	for i in range(len(p)):
		print(int(p[i]), end=' ')
	print()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
from itertools import accumulate
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	(n, m) = li()
	l1 = li()
	l2 = li2()
	index = {}
	for i in range(n):
		index[i] = l1[i]
	l = [[l1[i], l2[i]] for i in range(n)]
	l.sort(key=lambda x: x[0])
	ans = defaultdict(int)
	left1 = []
	right1 = []
	left2 = []
	right2 = []
	for i in range(n):
		if l[i][1] == 'L':
			if l[i][0] & 1:
				if len(right1):
					ans[right1[-1]] = abs(right1[-1] - l[i][0]) // 2
					ans[l[i][0]] = abs(right1[-1] - l[i][0]) // 2
					right1.pop()
				else:
					left1.append(l[i][0])
			elif len(right2):
				ans[right2[-1]] = abs(right2[-1] - l[i][0]) // 2
				ans[l[i][0]] = abs(right2[-1] - l[i][0]) // 2
				right2.pop()
			else:
				left2.append(l[i][0])
		elif l[i][0] & 1:
			right1.append(l[i][0])
		else:
			right2.append(l[i][0])
	for i in range(1, len(left1), 2):
		(ind1, ind2) = (left1[i - 1], left1[i])
		ans[ind1] = abs(ind1 - ind2) // 2 + ind1
		ans[ind2] = abs(ind1 - ind2) // 2 + ind1
	for i in range(1, len(left2), 2):
		(ind1, ind2) = (left2[i - 1], left2[i])
		ans[ind1] = abs(ind1 - ind2) // 2 + ind1
		ans[ind2] = abs(ind1 - ind2) // 2 + ind1
	for i in range(len(right1) - 1, 0, -2):
		(ind1, ind2) = (right1[i - 1], right1[i])
		ans[ind1] = abs(ind1 - ind2) // 2 + (m - ind2)
		ans[ind2] = abs(ind1 - ind2) // 2 + (m - ind2)
	for i in range(len(right2) - 1, 0, -2):
		(ind1, ind2) = (right2[i - 1], right2[i])
		ans[ind1] = abs(ind1 - ind2) // 2 + (m - ind2)
		ans[ind2] = abs(ind1 - ind2) // 2 + (m - ind2)
	if len(left1) & 1:
		left1 = left1[-1:]
	else:
		left1 = []
	if len(left2) & 1:
		left2 = left2[-1:]
	else:
		left2 = []
	if len(right1) & 1:
		right1 = right1[:1]
	else:
		right1 = []
	if len(right2) & 1:
		right2 = right2[:1]
	else:
		right2 = []
	if len(left1) and len(right1):
		(ind1, ind2) = (left1[0], right1[0])
		ans[ind1] = abs(ind1 - ind2) // 2 + (m - ind2) + ind1
		ans[ind2] = abs(ind1 - ind2) // 2 + (m - ind2) + ind1
	if len(left2) and len(right2):
		(ind1, ind2) = (left2[0], right2[0])
		ans[ind1] = abs(ind1 - ind2) // 2 + (m - ind2) + ind1
		ans[ind2] = abs(ind1 - ind2) // 2 + (m - ind2) + ind1
	for i in range(n):
		if index[i] not in ans:
			print(-1, end=' ')
		else:
			print(ans[index[i]], end=' ')
	print()


import math
import sys
from collections import Counter, defaultdict
import bisect

def helper(a, m):
	r = []
	l = []
	n = len(a)
	answer = []
	a = sorted(a, key=lambda x: x[0])
	for i in range(n):
		if a[i][2] == 'R':
			r.append(a[i])
		elif a[i][2] == 'L':
			if len(r) == 0:
				l.append(a[i])
			else:
				temp = r.pop()
				ans = (a[i][0] - temp[0]) // 2
				answer.append([a[i][1], ans])
				answer.append([temp[1], ans])
	i = 0
	while i < len(l) - 1:
		ans = (l[i][0] + l[i + 1][0]) // 2
		answer.append([l[i][1], ans])
		answer.append([l[i + 1][1], ans])
		i += 2
	if len(l) % 2:
		answer.append([l[-1][1], -1])
	i = 0
	r = r[::-1]
	while i < len(r) - 1:
		ans = m - (r[i][0] + r[i + 1][0]) // 2
		answer.append([r[i][1], ans])
		answer.append([r[i + 1][1], ans])
		i += 2
	if len(r) % 2:
		answer.append([r[-1][1], -1])
	if len(l) % 2 and len(r) % 2:
		ans = (2 * m + l[-1][0] - r[-1][0]) // 2
		answer.append([l[-1][1], ans])
		answer.append([r[-1][1], ans])
	elif len(r) % 2:
		answer.append([r[-1][1], -1])
	elif len(l) % 2:
		answer.append([l[-1][1], -1])
	return answer
for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	d = list(input().split(' '))
	even = []
	odd = []
	for i in range(n):
		if a[i] % 2:
			odd.append([a[i], i, d[i]])
		else:
			even.append([a[i], i, d[i]])
	evenAnswer = helper(even, m)
	oddAnswer = helper(odd, m)
	answer = [0 for i in range(n)]
	for i in range(len(evenAnswer)):
		answer[evenAnswer[i][0]] = evenAnswer[i][1]
	for i in range(len(oddAnswer)):
		answer[oddAnswer[i][0]] = oddAnswer[i][1]
	print(*answer)


def collide_after(indices):
	ans = [-1] * N
	indices.sort(key=lambda i: A[i])
	stack = []
	for i in indices:
		if D[i] == 'R':
			stack.append(i)
		elif len(stack) > 0:
			j = stack.pop()
			ans[i] = A[i] - A[j] >> 1
			ans[j] = ans[i]
		else:
			stack.append(i)
			A[i] = -A[i]
	while len(stack) >= 2:
		i = stack.pop()
		j = stack.pop()
		ans[i] = M - A[i] + (A[i] - A[j] >> 1)
		ans[j] = ans[i]
	return ans

def solve():
	even = [i for i in range(N) if A[i] % 2 == 0]
	odd = [i for i in range(N) if A[i] % 2 == 1]
	even_soln = collide_after(even)
	odd_soln = collide_after(odd)
	ans = [0] * N
	for i in range(N):
		if A[i] % 2 == 0:
			ans[i] = even_soln[i]
		else:
			ans[i] = odd_soln[i]
	return ans
test_cases = int(input())
for test_case in range(test_cases):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	D = input().split()
	print(*solve())


from collections import deque

def solver(robots, moves, end_point, length):
	positions = sorted([i for i in range(length)], key=lambda x: robots[x])
	position_even = [i for i in positions if robots[i] % 2 == 0]
	position_odd = [i for i in positions if robots[i] % 2 == 1]
	stack = deque()
	answer = [-1 for i in range(length)]
	for position in position_even:
		move = moves[position]
		if move == 'R':
			stack.append(position)
		if move == 'L':
			if len(stack) != 0:
				time = (robots[position] - robots[stack[-1]]) // 2
				answer[position] = answer[stack[-1]] = time
				stack.pop()
			else:
				stack.append(position)
				robots[position] = robots[position] * -1
	length_s = len(stack)
	while length_s >= 2:
		answer[stack[-1]] = answer[stack[-2]] = (2 * end_point - robots[stack[-1]] - robots[stack[-2]]) // 2
		stack.pop()
		stack.pop()
		length_s -= 2
	stack.clear()
	for position in position_odd:
		move = moves[position]
		if move == 'R':
			stack.append(position)
		if move == 'L':
			if len(stack) != 0:
				time = (robots[position] - robots[stack[-1]]) // 2
				answer[position] = answer[stack[-1]] = time
				stack.pop()
			else:
				stack.append(position)
				robots[position] = robots[position] * -1
	length_s = len(stack)
	while length_s >= 2:
		answer[stack[-1]] = answer[stack[-2]] = (2 * end_point - robots[stack[-1]] - robots[stack[-2]]) // 2
		stack.pop()
		stack.pop()
		length_s -= 2
	stack.clear()
	return answer
test_cases = int(input())
for case in range(test_cases):
	(length, end_point) = [int(i) for i in input().split()]
	robots = [int(i) for i in input().split()]
	moves = [i for i in input().split()]
	print(*solver(robots, moves, end_point, length))


def solve(robot, m, res):
	robot.sort()
	stack = []
	for (x, dire, i) in robot:
		if dire == 'L':
			if not stack:
				stack.append((i, -x))
			else:
				(i2, x2) = stack[-1]
				res[i] = res[i2] = (x - x2) // 2
				stack.pop()
		else:
			stack.append((i, x))
	while len(stack) >= 2:
		(i1, x1) = stack[-1]
		stack.pop()
		x1 = m + (m - x1)
		(i2, x2) = stack[-1]
		stack.pop()
		res[i1] = res[i2] = (x1 - x2) // 2
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	info = list(zip(map(int, input().split()), input().split()))
	robot = [[], []]
	for i in range(n):
		(x, dire) = info[i]
		robot[x & 1].append((x, dire, i))
	res = [-1 for i in range(n)]
	solve(robot[0], m, res)
	solve(robot[1], m, res)
	print(*res)


import sys

def check(arr):
	arr.sort(key=lambda x: x[1])
	stack = []
	for (idx, pos, way) in arr:
		if way == 'L':
			if not stack:
				stack.append((idx, -pos))
			else:
				temp = stack.pop()
				ans[idx] = ans[temp[0]] = (pos - temp[1]) // 2
		else:
			stack.append((idx, pos))
	while len(stack) > 1:
		fir = stack.pop()
		sec = stack.pop()
		ans[fir[0]] = ans[sec[0]] = (m + m - fir[1] - sec[1]) // 2
t = int(sys.stdin.readline())
for i in range(t):
	(n, m) = map(int, sys.stdin.readline().split())
	start = list(map(int, sys.stdin.readline().split()))
	direction = list(sys.stdin.readline().split())
	data = [[], []]
	ans = [-1] * len(start)
	for j in range(len(start)):
		data[start[j] % 2].append((j, start[j], direction[j]))
	check(data[0])
	check(data[1])
	print(*ans)


import sys, os, io
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	d = [i for i in input().split()]
	even = []
	odd = []
	for i in range(n):
		if a[i] % 2:
			odd.append([a[i], i, d[i]])
		else:
			even.append([a[i], i, d[i]])
	even.sort()
	odd.sort()
	ans = [-1] * n
	stack = []
	for i in range(len(even)):
		if even[i][2] == 'R':
			stack.append(even[i][:])
		elif len(stack) and stack[-1][2] == 'R':
			curr = stack.pop()
			ans[curr[1]] = abs(even[i][0] - curr[0]) // 2
			ans[even[i][1]] = abs(even[i][0] - curr[0]) // 2
		else:
			stack.append(even[i][:])
	rem = []
	temp = 0
	while len(stack) >= 2:
		if stack[-1][2] == stack[-2][2]:
			if stack[-1][2] == 'L' and temp == 0:
				stack.reverse()
				temp = 1
			aa = stack.pop()
			bb = stack.pop()
			if aa[2] == 'R':
				ans[aa[1]] = abs(aa[0] - bb[0]) // 2 + min(m - aa[0], m - bb[0])
				ans[bb[1]] = abs(aa[0] - bb[0]) // 2 + min(m - aa[0], m - bb[0])
			else:
				ans[aa[1]] = abs(aa[0] - bb[0]) // 2 + min(aa[0], bb[0])
				ans[bb[1]] = abs(aa[0] - bb[0]) // 2 + min(aa[0], bb[0])
		else:
			rem.append(stack.pop())
			stack.reverse()
			temp = 1
	if len(stack):
		rem.append(stack.pop())
	if len(rem) == 2:
		aa = rem.pop()
		bb = rem.pop()
		if aa[2] == 'R':
			(aa, bb) = (bb, aa)
		mi = min(aa[0], m - bb[0])
		pos1 = aa[0] - mi
		pos2 = bb[0] + mi
		diff = abs(pos2 - pos1) // 2
		extra = max(pos1, m - pos2)
		ans[aa[1]] = diff + extra + mi
		ans[bb[1]] = diff + extra + mi
	stack = []
	for i in range(len(odd)):
		if odd[i][2] == 'R':
			stack.append(odd[i][:])
		elif len(stack) and stack[-1][2] == 'R':
			curr = stack.pop()
			ans[curr[1]] = abs(odd[i][0] - curr[0]) // 2
			ans[odd[i][1]] = abs(odd[i][0] - curr[0]) // 2
		else:
			stack.append(odd[i][:])
	rem = []
	temp = 0
	while len(stack) >= 2:
		if stack[-1][2] == stack[-2][2]:
			if stack[-1][2] == 'L' and temp == 0:
				stack.reverse()
				temp = 1
			aa = stack.pop()
			bb = stack.pop()
			if aa[2] == 'R':
				ans[aa[1]] = abs(aa[0] - bb[0]) // 2 + min(m - aa[0], m - bb[0])
				ans[bb[1]] = abs(aa[0] - bb[0]) // 2 + min(m - aa[0], m - bb[0])
			else:
				ans[aa[1]] = abs(aa[0] - bb[0]) // 2 + min(aa[0], bb[0])
				ans[bb[1]] = abs(aa[0] - bb[0]) // 2 + min(aa[0], bb[0])
		else:
			rem.append(stack.pop())
			stack.reverse()
			temp = 1
	if len(stack):
		rem.append(stack.pop())
	if len(rem) == 2:
		aa = rem.pop()
		bb = rem.pop()
		if aa[2] == 'R':
			(aa, bb) = (bb, aa)
		mi = min(aa[0], m - bb[0])
		pos1 = aa[0] - mi
		pos2 = bb[0] + mi
		diff = abs(pos2 - pos1) // 2
		extra = max(pos1, m - pos2)
		ans[aa[1]] = diff + extra + mi
		ans[bb[1]] = diff + extra + mi
	print(*ans)


import sys
input = sys.stdin.readline

def solve(N, M, X, D):
	for i in range(len(X)):
		X[i] = (X[i], D[i], i)
	X.sort()
	ans = [-1 for _ in range(N)]
	stk = [[] for _ in range(2)]
	for (i, (x, d, idx)) in enumerate(X):
		parity = x % 2
		if d == 1:
			stk[parity].append((x, idx))
		elif stk[parity]:
			collider = stk[parity][-1]
			stk[parity].pop()
			dist = (x - collider[0]) // 2
			ans[idx] = ans[collider[1]] = dist
		else:
			stk[parity].append((-x, idx))
	for i in range(2):
		while len(stk[i]) > 1:
			first = stk[i][-1]
			stk[i].pop()
			second = stk[i][-1]
			stk[i].pop()
			dist = (M * 2 - first[0] - second[0]) // 2
			ans[first[1]] = ans[second[1]] = dist
	print(*ans)
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	X = list(map(int, input().split()))
	D = list(map(lambda x: -1 if x == 'L' else 1, input().split()))
	solve(N, M, X, D)


def main():
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	LR = input().split()
	Odd = []
	Even = []
	Index = {}
	Ans = [-1] * N
	for i in range(N):
		Index[A[i]] = i
		if A[i] % 2:
			Odd.append((A[i], 0 if LR[i] == 'R' else 1))
		else:
			Even.append((A[i], 0 if LR[i] == 'R' else 1))
	Stack = []
	Odd.sort()
	for (X, D) in Odd:
		if D:
			if Stack:
				X2 = Stack.pop()
				Time = (X - X2) // 2
				Ans[Index[X]] = Time
				Ans[Index[abs(X2)]] = Time
			else:
				Stack.append(-X)
		else:
			Stack.append(X)
	while len(Stack) >= 2:
		X = Stack.pop()
		X2 = Stack.pop()
		Time = (M + M - X - X2) // 2
		Ans[Index[X]] = Time
		Ans[Index[abs(X2)]] = Time
	Stack = []
	Even.sort()
	for (X, D) in Even:
		if D:
			if Stack:
				X2 = Stack.pop()
				Time = (X - X2) // 2
				Ans[Index[X]] = Time
				Ans[Index[abs(X2)]] = Time
			else:
				Stack.append(-X)
		else:
			Stack.append(X)
	while len(Stack) >= 2:
		X = Stack.pop()
		X2 = Stack.pop()
		Time = (M + M - X - X2) // 2
		Ans[Index[X]] = Time
		Ans[Index[abs(X2)]] = Time
	print(*Ans)
T = int(input())
for _ in range(T):
	main()


from collections import deque

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, m) = readIntArr()
		x = readIntArr()
		direction = input().split()

		def solve(indexes):
			indexes.sort(key=lambda i: x[i])
			rights = deque()
			for i in indexes:
				if direction[i] == 'R':
					rights.append(i)
				elif rights:
					j = rights.pop()
					xi = x[i]
					xj = x[j]
					if direction[j] == 'L':
						xj *= -1
					time = (xi - xj) // 2
					ans[i] = ans[j] = time
				else:
					rights.appendleft(i)
			while len(rights) >= 2:
				iRight = rights.pop()
				iLeft = rights.pop()
				xRight = x[iRight]
				if direction[iRight] == 'L':
					xRight *= -1
				xLeft = x[iLeft]
				if direction[iLeft] == 'L':
					xLeft *= -1
				xRight = m + m - xRight
				time = (xRight - xLeft) // 2
				ans[iRight] = ans[iLeft] = time
		ans = [-1] * n
		evenOdd = [[], []]
		for i in range(n):
			evenOdd[x[i] % 2].append(i)
		for indexes in evenOdd:
			solve(indexes)
		allans.append(ans)
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(i, j):
	print('? {} {}'.format(i, j))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(' '.join([str(x) for x in ans])))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True

def solve(arr, n, m, ansl):
	pre = []
	for i in arr:
		if i[1] == 'R':
			pre.append(i)
		elif len(pre) == 0:
			pre.append([-i[0], 'R', i[2]])
		else:
			x = (i[0] - pre[-1][0]) // 2
			ansl[i[2]] = x
			ansl[pre[-1][2]] = x
			pre.pop()
	while len(pre) > 1:
		a = pre.pop()
		b = pre.pop()
		x = m - (a[0] + b[0]) // 2
		ansl[a[2]] = x
		ansl[b[2]] = x
	return ansl
for _ in range(int(inp())):
	(n, m) = mp()
	arr = lmp()
	s = list(input().split())
	ansl = l1d(n, -1)
	odd = [[arr[i], s[i], i] for i in range(n) if arr[i] % 2]
	even = [[arr[i], s[i], i] for i in range(n) if arr[i] % 2 == 0]
	odd.sort()
	even.sort()
	ansl = solve(odd, len(odd), m, ansl)
	ansl = solve(even, len(even), m, ansl)
	print(*ansl)


import sys
import math
from itertools import *
from queue import LifoQueue
from collections import deque

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def powset(arr, length):
	out = []
	for i in range(0, length + 1):
		for j in combinations(arr, i):
			out.append(j)
	return out

def perm(arr):
	return list(permutations(arr))
for i in range(int(input())):
	(n, m) = map(int, input().split())
	rob = [int(i) for i in input().split()]
	d = [1 if i == 'R' else -1 for i in input().split()]
	odd = []
	even = []
	for i in range(n):
		if rob[i] % 2:
			odd.append([rob[i], d[i], i])
		else:
			even.append([rob[i], d[i], i])
	odd.sort(key=lambda x: x[0])
	even.sort(key=lambda x: x[0])
	stack = deque()
	l = []
	for i in odd:
		if len(stack) == 0 or i[1] == 1:
			stack.append(i)
		elif i[1] == -1:
			x = stack[-1][0]
			if stack[-1][1] == 1:
				l.append(stack.pop())
				l.append(i)
				l[-1].append((i[0] - x) // 2)
				l[-2].append((i[0] - x) // 2)
			elif stack[-1][1] == -1:
				l.append(stack.pop())
				l.append(i)
				l[-1].append((x + i[0]) // 2)
				l[-2].append((x + i[0]) // 2)
	t = len(stack)
	if t % 2:
		while t > 1:
			l.append(stack.pop())
			l.append(stack.pop())
			l[-1].append(m - (l[-1][0] + l[-2][0]) // 2)
			l[-2].append(m - (l[-1][0] + l[-2][0]) // 2)
			t -= 2
		l.append(stack.pop())
		l[-1].append(-1)
	elif t > 0:
		while t > 2:
			l.append(stack.pop())
			l.append(stack.pop())
			l[-1].append(m - (l[-1][0] + l[-2][0]) // 2)
			l[-2].append(m - (l[-1][0] + l[-2][0]) // 2)
			t -= 2
		a = stack.pop()
		b = stack.pop()
		if b[1] == -1:
			l.append(a)
			l.append(b)
			l[-1].append(m + (b[0] - a[0]) // 2)
			l[-2].append(m + (b[0] - a[0]) // 2)
		else:
			l.append(a)
			l.append(b)
			l[-1].append(m - (l[-1][0] + l[-2][0]) // 2)
			l[-2].append(m - (l[-1][0] + l[-2][0]) // 2)
	for i in even:
		if len(stack) == 0 or i[1] == 1:
			stack.append(i)
		elif i[1] == -1:
			x = stack[-1][0]
			if stack[-1][1] == 1:
				l.append(stack.pop())
				l.append(i)
				l[-1].append((i[0] - x) // 2)
				l[-2].append((i[0] - x) // 2)
			elif stack[-1][1] == -1:
				l.append(stack.pop())
				l.append(i)
				l[-1].append((x + i[0]) // 2)
				l[-2].append((x + i[0]) // 2)
	t = len(stack)
	if t % 2:
		while t != 1:
			l.append(stack.pop())
			l.append(stack.pop())
			l[-1].append(m - (l[-1][0] + l[-2][0]) // 2)
			l[-2].append(m - (l[-1][0] + l[-2][0]) // 2)
			t -= 2
		l.append(stack.pop())
		l[-1].append(-1)
	elif t != 0:
		while t != 2:
			l.append(stack.pop())
			l.append(stack.pop())
			l[-1].append(m - (l[-1][0] + l[-2][0]) // 2)
			l[-2].append(m - (l[-1][0] + l[-2][0]) // 2)
			t -= 2
		a = stack.pop()
		b = stack.pop()
		if b[1] == -1:
			l.append(a)
			l.append(b)
			l[-1].append(m + (b[0] - a[0]) // 2)
			l[-2].append(m + (b[0] - a[0]) // 2)
		else:
			l.append(a)
			l.append(b)
			l[-1].append(m - (l[-1][0] + l[-2][0]) // 2)
			l[-2].append(m - (l[-1][0] + l[-2][0]) // 2)
	l.sort(key=lambda x: x[2])
	for i in range(n):
		print(l[i][3], end=' ')
	print('')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = input().split()
	stack0 = []
	stack1 = []
	ans = [-1] * n
	C = sorted([(a, b, i) for (i, (a, b)) in enumerate(zip(A, B))])
	for (a, b, i) in C:
		if not a % 2:
			if b == 'L':
				if stack0:
					(x, j) = stack0.pop()
					ans[i] = ans[j] = (a - x) // 2
				else:
					stack0.append((-a, i))
			else:
				stack0.append((a, i))
		elif b == 'L':
			if stack1:
				(x, j) = stack1.pop()
				ans[i] = ans[j] = (a - x) // 2
			else:
				stack1.append((-a, i))
		else:
			stack1.append((a, i))
	while len(stack0) >= 2:
		(x, i) = stack0.pop()
		(y, j) = stack0.pop()
		ans[i] = ans[j] = (2 * m - x - y) // 2
	while len(stack1) >= 2:
		(x, i) = stack1.pop()
		(y, j) = stack1.pop()
		ans[i] = ans[j] = (2 * m - x - y) // 2
	print(*ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	time = [-1] * n
	x = list(map(int, input().split()))
	dir = input().split()
	a = sorted(list(zip(x, dir, list(range(n)))))
	(x, dir, idx) = map(list, list(zip(*a)))
	s = []
	s2 = []
	for i in range(n):
		if x[i] & 1:
			if dir[i] == 'R':
				s.append(i)
			elif s:
				j = s.pop()
				time[j] = time[i] = abs(x[j] - x[i]) // 2
		elif dir[i] == 'R':
			s2.append(i)
		elif s2:
			j = s2.pop()
			time[j] = time[i] = abs(x[j] - x[i]) // 2
	s = []
	s2 = []
	for i in range(n):
		if time[i] == -1 and dir[i] == 'L':
			if x[i] & 1:
				if s:
					j = s.pop()
					time[j] = time[i] = abs(x[j] - x[i]) // 2 + x[j]
				else:
					s.append(i)
			elif s2:
				j = s2.pop()
				time[j] = time[i] = abs(x[j] - x[i]) // 2 + x[j]
			else:
				s2.append(i)
	s = []
	s2 = []
	for i in range(n - 1, -1, -1):
		if time[i] == -1 and dir[i] == 'R':
			if x[i] & 1:
				if s:
					j = s.pop()
					time[j] = time[i] = abs(x[j] - x[i]) // 2 + m - x[j]
				else:
					s.append(i)
			elif s2:
				j = s2.pop()
				time[j] = time[i] = abs(x[j] - x[i]) // 2 + m - x[j]
			else:
				s2.append(i)
	L_loc = R_loc = -1
	L_loc2 = R_loc2 = -1
	for i in range(n):
		if x[i] & 1:
			if time[i] == -1 and dir[i] == 'L':
				L_loc = i
		elif time[i] == -1 and dir[i] == 'L':
			L_loc2 = i
	for i in range(n - 1, -1, -1):
		if x[i] & 1:
			if time[i] == -1 and dir[i] == 'R':
				R_loc = i
		elif time[i] == -1 and dir[i] == 'R':
			R_loc2 = i
	if L_loc != -1 and R_loc != -1:
		time[L_loc] = time[R_loc] = (2 * m - (x[R_loc] - x[L_loc])) // 2
	if L_loc2 != -1 and R_loc2 != -1:
		time[L_loc2] = time[R_loc2] = (2 * m - (x[R_loc2] - x[L_loc2])) // 2
	true_time = [0] * n
	for i in range(n):
		true_time[idx[i]] = time[i]
	print(*true_time)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	x = [*map(int, input().split())]
	d = [*input().split()]
	ind = sorted(range(n), key=lambda i: x[i])
	a = [-1] * n
	ls = []
	rs = []
	for j in range(n):
		i = ind[j]
		if x[i] % 2 == 1:
			continue
		if d[i] == 'R':
			rs.append(i)
		elif not ls and (not rs):
			ls.append(i)
		elif rs:
			a[i] = a[rs[-1]] = (x[i] - x[rs[-1]]) // 2
			rs.pop()
		else:
			a[i] = a[ls[-1]] = x[ls[-1]] + (x[i] - x[ls[-1]]) // 2
			ls.pop()
	while len(rs) >= 2:
		i = rs[-1]
		j = rs[-2]
		rs.pop()
		rs.pop()
		di = m - x[i]
		dj = m - x[j]
		a[i] = a[j] = di + (dj - di) // 2
	if ls and rs:
		a[ls[0]] = a[rs[0]] = (m + x[ls[0]] + (m - x[rs[0]])) // 2
	ls = []
	rs = []
	for j in range(n):
		i = ind[j]
		if x[i] % 2 == 0:
			continue
		if d[i] == 'R':
			rs.append(i)
		elif not ls and (not rs):
			ls.append(i)
		elif rs:
			a[i] = a[rs[-1]] = (x[i] - x[rs[-1]]) // 2
			rs.pop()
		else:
			a[i] = a[ls[-1]] = x[ls[-1]] + (x[i] - x[ls[-1]]) // 2
			ls.pop()
	while len(rs) >= 2:
		i = rs[-1]
		j = rs[-2]
		rs.pop()
		rs.pop()
		di = m - x[i]
		dj = m - x[j]
		a[i] = a[j] = di + (dj - di) // 2
	if ls and rs:
		a[ls[0]] = a[rs[0]] = (m + x[ls[0]] + (m - x[rs[0]])) // 2
	print(*a)


from collections import deque
totCases = int(input())
for _ in range(totCases):
	(n, m) = [int(i) for i in input().split(' ')]
	stpos = [int(i) for i in input().split(' ')]
	direc = [i.upper() for i in input().split(' ')]
	rob = sorted([(stpos[i], direc[i], i) for i in range(n)])
	ans = [-1 for i in range(n)]
	(evs, ods) = (deque(), deque())
	for i in range(n):
		targ = rob[i]
		que = ods if targ[0] & 1 == 1 else evs
		if targ[1] == 'R':
			que.append(targ)
		elif not que:
			que.append((-targ[0], 'R', targ[-1]))
		else:
			time = targ[0] - que[-1][0] >> 1
			ans[targ[-1]] = time
			ans[que.pop()[-1]] = time
	for que in [evs, ods]:
		while len(que) >= 2:
			l = que.pop()
			r = que.pop()
			r = (m * 2 - r[0], r[1], r[2])
			time = r[0] - l[0] >> 1
			ans[l[-1]] = time
			ans[r[-1]] = time
	for it in ans:
		print(it, end=' ')
	print()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	p = list(map(int, input().split()))
	d = list(map(str, input().split()))
	c = {}
	for i in range(len(p)):
		ele = p[i]
		c[ele] = i
	e = []
	o = []
	ans = [0] * n
	for i in range(n):
		x = p[i]
		if x % 2:
			o.append((x, d[i]))
		else:
			e.append((x, d[i]))
	e.sort()
	o.sort()
	stack = []
	for x in e:
		di = x[0]
		h = x[1]
		if h == 'R':
			stack.append(x)
		elif len(stack) == 0:
			stack.append(x)
		elif stack[-1][1] == 'R':
			cnt = 0
			y = stack.pop()
			diff = (di - y[0]) // 2
			cnt += diff
			i1 = c[di]
			i2 = c[y[0]]
			ans[i1] = cnt
			ans[i2] = cnt
		else:
			cnt = 0
			y = stack.pop()
			diff = (di - y[0]) // 2
			cnt += diff
			cnt += y[0]
			i1 = c[di]
			i2 = c[y[0]]
			ans[i1] = cnt
			ans[i2] = cnt
	while len(stack) > 1:
		e2 = stack.pop()
		e1 = stack.pop()
		d2 = e2[0]
		d1 = e1[0]
		if e2[1] == 'R' and e1[1] == 'R':
			cnt = 0
			diff = (d2 - d1) // 2
			cnt += diff
			cnt += m - d2
			i1 = c[d2]
			i2 = c[d1]
			ans[i1] = cnt
			ans[i2] = cnt
			continue
		z1 = d1
		z2 = d2
		dis = max(abs(m - d2), d1)
		cnt = dis
		d1 = abs(d1 - dis)
		d2 = (d2 + dis) % m
		d2 = m - d2
		diff = abs(d2 - d1) // 2
		cnt += diff
		i1 = c[z2]
		i2 = c[z1]
		ans[i1] = cnt
		ans[i2] = cnt
		continue
	if len(stack) == 1:
		ele = stack.pop()
		d1 = ele[0]
		i1 = c[d1]
		ans[i1] = -1
	stack = []
	for x in o:
		h = x[1]
		di = x[0]
		if h == 'R':
			stack.append(x)
		elif len(stack) == 0:
			stack.append(x)
		elif stack[-1][1] == 'R':
			cnt = 0
			y = stack.pop()
			diff = (di - y[0]) // 2
			cnt += diff
			i1 = c[di]
			i2 = c[y[0]]
			ans[i1] = cnt
			ans[i2] = cnt
		else:
			cnt = 0
			y = stack.pop()
			diff = (di - y[0]) // 2
			cnt += diff
			cnt += y[0]
			i1 = c[di]
			i2 = c[y[0]]
			ans[i1] = cnt
			ans[i2] = cnt
	while len(stack) > 1:
		e2 = stack.pop()
		e1 = stack.pop()
		d2 = e2[0]
		d1 = e1[0]
		if e2[1] == 'R' and e1[1] == 'R':
			cnt = 0
			diff = (d2 - d1) // 2
			cnt += diff
			cnt += m - d2
			i1 = c[d2]
			i2 = c[d1]
			ans[i1] = cnt
			ans[i2] = cnt
			continue
		z1 = d1
		z2 = d2
		dis = max(abs(m - d2), d1)
		cnt = dis
		d1 = abs(d1 - dis)
		d2 = (d2 + dis) % m
		d2 = m - d2
		diff = abs(d2 - d1) // 2
		cnt += diff
		i1 = c[z2]
		i2 = c[z1]
		ans[i1] = cnt
		ans[i2] = cnt
		continue
	if len(stack) == 1:
		ele = stack.pop()
		d1 = ele[0]
		i1 = c[d1]
		ans[i1] = -1
	print(*ans)


import heapq

def choques(eles, k):
	trenesito = []
	res = {}
	for (pos, sen) in eles:
		if sen == 1 and len(trenesito) != 0:
			(pos2, sen2) = heapq.heappop(trenesito)
			choque = (pos2 - pos) // 2
			res[pos] = choque
			if sen2 == -1:
				res[pos2] = choque
			else:
				res[k + k - pos2] = choque
			continue
		if sen == -1:
			heapq.heappush(trenesito, (pos, sen))
		else:
			heapq.heappush(trenesito, (k + k - pos, sen))
	while len(trenesito) != 0:
		(pos, sen) = heapq.heappop(trenesito)
		if len(trenesito) == 0:
			if sen == 1:
				res[k + k - pos] = -1
			else:
				res[pos] = -1
			break
		(pos2, sen2) = heapq.heappop(trenesito)
		choque = (pos + pos2) // 2
		if sen == -1:
			res[pos] = choque
		else:
			res[k + k - pos] = choque
		if sen2 == -1:
			res[pos2] = choque
		else:
			res[k + k - pos2] = choque
	return res

def solvecaso():
	(n, m) = map(int, input().split())
	coords = list(map(int, input().split()))
	dirs = list(map(lambda c: 1 if c == 'R' else -1, input().split()))
	elespar = []
	elesnon = []
	for ele in zip(coords, dirs):
		if ele[0] % 2:
			elesnon.append(ele)
		else:
			elespar.append(ele)
	elesnon.sort(reverse=True)
	elespar.sort(reverse=True)
	choquesnon = choques(elesnon, m)
	choquespar = choques(elespar, m)
	for ele in coords:
		if ele % 2:
			print(choquesnon[ele], end=' ')
		else:
			print(choquespar[ele], end=' ')
	print()
	return 0
casos = int(input())
for caso in range(1, casos + 1):
	result = solvecaso()


import time
import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string, heapq as h
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def getInt():
	return int(input())

def getStrs():
	return input().split()

def getInts():
	return list(map(int, input().split()))

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def getBin():
	return list(map(int, list(input())))

def isInt(s):
	return '0' <= s[0] <= '9'

def ceil_(a, b):
	return a // b + (a % b > 0)

def solve():
	(N, M) = getInts()
	X = getInts()
	X = sorted([(x, i) for (i, x) in enumerate(X)])
	dirs = getStrs()
	evens = []
	odds = []
	ans = [-1] * N
	for (x, i) in X:
		if x % 2 == 0:
			if dirs[i] == 'L':
				if evens:
					(idx, pos) = evens.pop()
					T = abs(x - pos) // 2
					ans[idx] = ans[i] = T
				else:
					evens.append((i, -x))
			else:
				evens.append((i, x))
		elif dirs[i] == 'L':
			if odds:
				(idx, pos) = odds.pop()
				T = abs(x - pos) // 2
				ans[idx] = ans[i] = T
			else:
				odds.append((i, -x))
		else:
			odds.append((i, x))
	while len(evens) > 1:
		(i1, pos1) = evens.pop()
		pos1 = M + (M - pos1)
		(i2, pos2) = evens.pop()
		T = abs(pos1 - pos2) // 2
		ans[i1] = ans[i2] = T
	while len(odds) > 1:
		(i1, pos1) = odds.pop()
		pos1 = M + (M - pos1)
		(i2, pos2) = odds.pop()
		T = abs(pos1 - pos2) // 2
		ans[i1] = ans[i2] = T
	print(*ans)
	return
for _ in range(getInt()):
	solve()


import os, sys
from io import BytesIO, IOBase

def solve(m, pairs, ans):
	st = []
	for (i, j, k) in pairs:
		if j == 'R':
			st.append((i, j, k))
		elif len(st) and st[-1][1] == 'R':
			z = st.pop()
			ans[z[2]] = ans[k] = abs(z[0] - i) // 2
		else:
			st.append((i, j, k))
	prev = -1
	for (i, j, k) in st:
		if j == 'R':
			break
		if prev == -1:
			prev = (i, j, k)
		else:
			ans[prev[2]] = ans[k] = prev[0] + abs(prev[0] - i) // 2
			prev = -1
	prev1 = -1
	for (i, j, k) in reversed(st):
		if j == 'L':
			break
		if prev1 == -1:
			prev1 = (i, j, k)
		else:
			ans[prev1[2]] = ans[k] = m - prev1[0] + abs(prev1[0] - i) // 2
			prev1 = -1
	if prev != -1 and prev1 != -1:
		ans[prev[2]] = ans[prev1[2]] = m + (prev[0] - prev1[0]) // 2

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		x = list(map(int, input().split()))
		dire = input().split()
		rr = sorted(range(n), key=lambda xx: x[xx])
		dire = [dire[rr[i]] for i in range(n)]
		x.sort()
		ans = [-1] * n
		solve(m, [(x[i], dire[i], i) for i in range(n) if x[i] & 1], ans)
		solve(m, [(x[i], dire[i], i) for i in range(n) if not x[i] & 1], ans)
		ans1 = [-1] * len(ans)
		for i in range(len(ans)):
			ans1[rr[i]] = ans[i]
		print(*ans1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()