Under construction

Still being built. Things may change

Heaps

Time limit1.2sMemory limit1024 MB

Summary
Given N heaps of big stones and small pebbles, decide whether the first player wins when each removed stone must be replaced by at least K pebbles.
Level

Medium7 of 10

Topics
Game theory, Math, Dynamic programming
Solved
No attempts yet

Problem

Nini and Mimi are playing a game with NN heaps of stones and pebbles. Each heap ii has BiB_i big stones and SiS_i small pebbles. The players take turns making moves, and a player who has no move left loses. A move chooses a non-empty heap ii and removes some stones and/or pebbles from it. Specifically, the player removes XX stones and YY pebbles, where 0≤X≤Bi0 \le X \le B_i, 0≤Y≤Si0 \le Y \le S_i, and X+Y>0X + Y > 0. Every removed stone must be replaced with at least KK pebbles. So when X≥1X \ge 1, the player first removes YY pebbles, then adds back ZZ pebbles from an infinite supply, where Z≥KXZ \ge KX and ZZ is a natural number. Nini moves first. Before her move, she wants to know whether she can win if both players play optimally.

Input

The first line contains KK and QQ. Then QQ independent tests follow, all using the same KK. Each test starts with a line containing NN. The next NN lines each contain BiB_i and SiS_i for one heap.

Output

Print QQ lines, one answer per test, in the input order. Print Win if Nini can win, and Loss otherwise.

Constraints

  • 1≤Q≤101 \le Q \le 10
  • 1≤N≤1041 \le N \le 10^4
  • 0≤K,Bi≤30000 \le K, B_i \le 3000
  • 0≤Si≤1070 \le S_i \le 10^7

Examples1

  1. Example 1

    Input
    3 2
    2
    1 5
    3 2
    3
    0 3
    2 1
    3 2
    
    Expected output
    Win
    Loss