Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.

In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the others are planets. There's a monster in one of the planet. Rick and Morty don't know on which one yet, only that he's not initially in the black hole, but Unity will inform them before the game starts. But for now, they want to be prepared for every possible scenario. [Image] 

Each one of them has a set of numbers between 1 and n - 1 (inclusive). Rick's set is s_1 with k_1 elements and Morty's is s_2 with k_2 elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like x from his set and the monster will move to his x-th next object from its current position (clockwise). If after his move the monster gets to the black hole he wins.

Your task is that for each of monster's initial positions and who plays first determine if the starter wins, loses, or the game will stuck in an infinite loop. In case when player can lose or make game infinity, it more profitable to choose infinity game.


-----Input-----

The first line of input contains a single integer n (2 ≤ n ≤ 7000) — number of objects in game.

The second line contains integer k_1 followed by k_1 distinct integers s_{1, 1}, s_{1, 2}, ..., s_{1, }k_1 — Rick's set.

The third line contains integer k_2 followed by k_2 distinct integers s_{2, 1}, s_{2, 2}, ..., s_{2, }k_2 — Morty's set

1 ≤ k_{i} ≤ n - 1 and 1 ≤ s_{i}, 1, s_{i}, 2, ..., s_{i}, k_{i} ≤ n - 1 for 1 ≤ i ≤ 2.


-----Output-----

In the first line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.

Similarly, in the second line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Morty plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.


-----Examples-----
Input
5
2 3 2
3 1 2 3

Output
Lose Win Win Loop
Loop Win Win Win

Input
8
4 6 2 3 4
2 3 6

Output
Win Win Win Win Win Win Win
Lose Win Lose Lose Win Lose Lose

Difficulty: HARD
Tags: Dynamic programming

Graph traversal

Game theory
Skill types: Dynamic programming

Starter code:

Solutions:
f = lambda : list(map(int, input().split()))[1:]
n = int(input())
(s, p, q) = ([], [], [])
for x in [0, 1]:
	r = f()
	s.append(r)
	t = [len(r)] * n
	t[0] = 0
	p.append(t)
	q.append((x, 0))
while q:
	(x, i) = q.pop()
	y = 1 - x
	for d in s[y]:
		j = (i - d) % n
		if p[y][j] < 1:
			continue
		p[y][j] = -1
		for d in s[x]:
			k = (j - d) % n
			if p[x][k] < 1:
				continue
			p[x][k] -= 1
			if p[x][k] == 0:
				q.append((x, k))
for x in [0, 1]:
	print(*[['Lose', 'Loop', 'Win'][min(q, 1)] for q in p[x][1:]])


import queue
n = int(input())
sR = list(map(int, input().split()[1:]))
sM = list(map(int, input().split()[1:]))
s = [sR, sM]
UNK = -1
WIN = 2
LOSE = 3
A = [[UNK] * n for i in range(2)]
CNT = [[0] * n for i in range(2)]
V = [[False] * n for i in range(2)]
A[0][0] = LOSE
A[1][0] = LOSE
Q = queue.Queue()
Q.put((0, 0))
Q.put((1, 0))
while not Q.empty():
	(turn, planet) = Q.get()
	prev_turn = 1 - turn
	for diff in s[prev_turn]:
		prev_planet = (n + planet - diff) % n
		if prev_planet == 0:
			continue
		if A[turn][planet] == LOSE:
			A[prev_turn][prev_planet] = WIN
		elif A[turn][planet] == WIN:
			CNT[prev_turn][prev_planet] += 1
		if CNT[prev_turn][prev_planet] == len(s[prev_turn]):
			A[prev_turn][prev_planet] = LOSE
		if A[prev_turn][prev_planet] != UNK and (not V[prev_turn][prev_planet]):
			Q.put((prev_turn, prev_planet))
			V[prev_turn][prev_planet] = True
print(' '.join(['Win' if A[0][i] == WIN else 'Lose' if A[0][i] == LOSE else 'Loop' for i in range(1, n)]))
print(' '.join(['Win' if A[1][i] == WIN else 'Lose' if A[1][i] == LOSE else 'Loop' for i in range(1, n)]))


RESULT = ['Lose', 'Loop', 'Win']

class Player(object):

	def __init__(self):
		super(Player, self).__init__()
		self.a = list(map(int, input().split()))[1:]
		self.f = [len(self.a)] * n
		self.f[0] = 0

	def prev(self, i):
		for x in self.a:
			if self.f[(i - x) % n] > 0:
				yield ((i - x) % n)

	def print_result(self):
		print(*[RESULT[min(x, 1)] for x in self.f[1:]])
n = int(input())
(a, b) = (Player(), Player())
q = [(a, b, 0), (b, a, 0)]
while q:
	(x, y, i) = q.pop()
	for j in y.prev(i):
		y.f[j] = -1
		for k in x.prev(j):
			x.f[k] -= 1
			if x.f[k] == 0:
				q.append((x, y, k))
a.print_result()
b.print_result()


import sys
n = int(input())
(k1, *A) = [int(x) for x in input().split()]
(k2, *B) = [int(x) for x in input().split()]
DPA = [None] * n
DPA[0] = False
counterA = [k1] * n
counterA[0] = -1
DPB = [None] * n
DPB[0] = False
counterB = [k2] * n
counterB[0] = -1
QA = [0]
QB = [0]
while QA or QB:
	while QA:
		i = QA.pop()
		if DPA[i] == False:
			for b in B:
				if i != b:
					if not DPB[i - b]:
						QB.append((i - b) % n)
					DPB[i - b] = True
		elif DPA[i]:
			for b in B:
				counterB[i - b] -= 1
				if not counterB[i - b]:
					DPB[i - b] = False
					QB.append((i - b) % n)
	while QB:
		i = QB.pop()
		if DPB[i] == False:
			for a in A:
				if i != a:
					if not DPA[i - a]:
						QA.append((i - a) % n)
					DPA[i - a] = True
		elif DPB[i]:
			for a in A:
				counterA[i - a] -= 1
				if not counterA[i - a]:
					DPA[i - a] = False
					QA.append((i - a) % n)

def f(x):
	if x == None:
		return 'Loop'
	if x:
		return 'Win'
	return 'Lose'
print(*[f(x) for x in DPA[1:]])
print(*[f(x) for x in DPB[1:]])


from sys import stdin, stdout

def ri():
	return map(int, input().split())
n = int(input())
a = list(ri())
b = list(ri())
a = a[1:]
b = b[1:]
T = [[-1 for i in range(2)] for j in range(n)]
T[0][0] = 1
T[0][1] = 0
for j in range(10 ** 9):
	c = 0
	for i in range(n - 1, -1, -1):
		flag = 0
		for k in a:
			ii = (i + k) % n
			if ii == 0 or T[ii][1] == 0:
				if T[i][0] != 0:
					c = 1
				T[i][0] = 0
				break
			if T[ii][1] != 1:
				flag = 1
		else:
			if flag == 0:
				if T[i][0] != 1:
					c = 1
				T[i][0] = 1
		flag = 0
		for k in b:
			ii = (i + k) % n
			if ii == 0 or T[ii][0] == 1:
				if T[i][1] != 1:
					c = 1
				T[i][1] = 1
				break
			if T[ii][0] != 0:
				flag = 1
		else:
			if flag == 0:
				if T[i][1] != 0:
					c = 1
				T[i][1] = 0
	if c == 0:
		break
ansa = ['Win', 'Lose', 'Loop']
ansb = ['Lose', 'Win', 'Loop']
aa = [ansa[T[i][0]] for i in range(1, n)]
bb = [ansb[T[i][1]] for i in range(1, n)]
print(' '.join(aa))
print(' '.join(bb))


class T:
	h = ('Lose', 'Loop', 'Win')

	def __init__(t):
		t.s = list(map(int, input().split()))[1:]
		t.p = [len(t.s)] * n
		t.p[0] = 0

	def f(t, i):
		for d in t.s:
			j = (i - d) % n
			if t.p[j] > 0:
				yield j

	def g(t):
		print(*[t.h[min(q, 1)] for q in t.p[1:]])
n = int(input())
(r, m) = (T(), T())
q = [(r, m, 0), (m, r, 0)]
while q:
	(x, y, i) = q.pop()
	for j in y.f(i):
		y.p[j] = -1
		for k in x.f(j):
			x.p[k] -= 1
			if not x.p[k]:
				q.append((x, y, k))
r.g()
m.g()