Under construction

Still being built. Things may change

Grid Game 3-angle

Time limit1sMemory limit2048 MB

Summary
Given stones on a triangular grid of up to 1e9 rows, decide whether the first player wins the game where each move removes up to K stones and adds up to K stones to cells below.
Level

Hard9 of 10

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

Problem

Your friends, Anda and Kamu, want to play a game called Grid Game and ask you to be the gamemaster. As the gamemaster, you set up a triangular grid of size NN. The grid has NN rows, numbered from 11 to NN. Row rr has rr cells, and the ccth cell of row rr is denoted (r,c)(r, c).

Before the game starts, MM different cells (numbered from 11 to MM) are chosen. At cell (Ri,Ci)(R_i, C_i), you add AiA_i stones. You then give Anda and Kamu an integer KK and start the game.

Anda and Kamu take turns, with Anda going first. On a turn, a player does the following.

  • Chooses a cell (r,c)(r, c) with at least one stone on it.
  • Removes at least one and at most KK stones from the chosen cell.
  • For each cell (x,y)(x, y) with r+1≤x≤min⁡(N,r+K)r+1 ≤ x ≤ \min(N, r+K) and c≤y≤c+x−rc ≤ y ≤ c+x-r, adds zero or more stones, but at most KK, to that cell.

The following illustrations show all the cells where stones can be added for K=3K = 3. The left one chooses cell (2,1)(2, 1), and the right one chooses cell (4,3)(4, 3).

A player who cannot complete a turn because no stones remain on the grid loses, and the opposing player wins. Determine who wins if both players play optimally.

Input

The first line contains an integer TT (1≤T≤1001 ≤ T ≤ 100), the number of test cases.

Each test case starts with a line containing three integers NN, MM, and KK (1≤N≤1091 ≤ N ≤ 10^9; 1≤M,K≤2000001 ≤ M, K ≤ 200000). Each of the next MM lines contains three integers RiR_i, CiC_i, and AiA_i (1≤Ci≤Ri≤N1 ≤ C_i ≤ R_i ≤ N; 1≤Ai≤1091 ≤ A_i ≤ 10^9). The pairs (Ri,Ci)(R_i, C_i) are distinct.

The sum of MM over all test cases does not exceed 200000.

Output

For each test case, output one line with the player who wins if both play optimally. Output Anda if Anda, the first player, wins. Otherwise, output Kamu.

Examples1

  1. Example 1

    Input
    3
    2 2 4
    1 1 3
    2 1 2
    100 2 1
    4 1 10
    4 4 10
    10 5 2
    1 1 4
    3 1 2
    4 2 5
    2 2 1
    5 3 4
    
    Expected output
    Anda
    Kamu
    Anda