This page is still under construction.

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

Professor Laugh's Numbers

Time limit1sMemory limit128 MB

Summary
Given a prime p, exponent e, and queries n, decide whether n is an e-th power residue modulo p.
Level

Medium7 of 10

Topics
Number theory, Math, Binary search, Divide and conquer
Solved
No attempts yet

Problem

Professor Byteman Laugh studies prime numbers.

For a prime p>2p > 2, an integer e>1e > 1, and an integer nn with 1≤n<p1 \le n < p, we say that nn is (p,e)(p, e)-interesting if there exists a natural number xx such that xe≡n(modp),x^e \equiv n \pmod{p}, that is, xex^e and nn leave the same remainder when divided by pp.

Write a program that reads a prime pp, an exponent ee, and a sequence of numbers, and then decides for each number whether it is (p,e)(p, e)-interesting.

Input

The first line contains two integers separated by a single space: a prime number pp and an exponent ee (3≤p≤2323 \le p \le 2^{32}, 2≤e<2322 \le e < 2^{32}).

The second line contains one integer kk, the number of queries (1≤k≤151 \le k \le 15).

Each of the next kk lines contains one integer nin_i (1≤ni≤p−11 \le n_i \le p - 1).

Output

Print exactly kk lines. Line ii (1≤i≤k1 \le i \le k) must contain a single word: TAK (yes) if nin_i is (p,e)(p, e)-interesting, or NIE (no) otherwise.

Examples1

  1. Example 1

    Input
    17 2
    5
    1
    9
    3
    7
    6
    
    Expected output
    TAK
    TAK
    NIE
    NIE
    NIE