This page is still under construction.

Parts of this page are still being built. What you see may change.

The Existence of N

Time limit5sMemory limit128 MB

Summary
Given a prime p, exponent m, and residue a, decide whether some positive n makes n^n + n^m congruent to a mod p.
Level

Medium7 of 10

Topics
Number theory, Math
Solved
No attempts yet

Problem

You are given a prime pp, a positive integer mm, and an integer aa with 0≤a<p0 \le a < p.

Determine whether there exists a positive integer nn such that nn+nm≡a(modp)n^n + n^m \equiv a \pmod{p}.

Input

The first line contains the number of test cases dd (1≤d≤3001 \le d \le 300).

Each of the next dd lines contains three integers pp, aa, and mm (2≤p≤1092 \le p \le 10^9, 0≤a<p0 \le a < p, 1≤m≤201 \le m \le 20, m<pm < p). pp is always prime.

Output

For each test case, print one line. If there exists a positive integer n<101000n < 10^{1000} satisfying nn+nm≡a(modp)n^n + n^m \equiv a \pmod{p}, print TAK; otherwise print NIE.

Examples2

  1. Example 1

    Input
    2
    11 3 1
    11 8 2
    
    Expected output
    TAK
    TAK
    
  2. Example 2

    Input
    2
    2 1 1
    2 0 1
    
    Expected output
    NIE
    TAK