1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ilo {

    public List<Long> fib = new ArrayList<Long>();

    public ilo() {
        fib.add(0L);
    }

    private void fillMax(Long max) {
        Long l = 2l;
        while (getLastFibValue() <= max) {
            getFib(l++);
        }
    }

    public String canI(Long val) {
        fillMax(val);
        List<Long> tmp = getSubstrFibArray(val);
        for (Integer i = 0; i < tmp.size() + 1; i++) {
            for (Integer j = i; j < tmp.size() + 1; j++) {
                if (fib.get(j) * fib.get(i) == val) {
                    return "TAK";
                }
            }
        }
        return "NIE";
    }

    private Long getFib(Long number) {
        Long value;
        if (number < 2L) {
            value = number;
        } else if (!fib.isEmpty() && fib.size() > Integer.valueOf(number.toString())) {
            return fib.get(Integer.valueOf(number.toString()));
        } else {
            value = getFib(number - 2L) + getFib(number - 1L);
            fib.add(value);
        }
        return value;
    }

    public Long getLastFibValue() {
        return fib.get(fib.size()-1);
    }

    public Integer getLastFibPosition() {
        return fib.size() - 1;
    }
//
//    

    private List<Long> getSubstrFibArray(Long maxValue) {
        return fib.subList(0, getFibPosition(maxValue));
    }
//

    private Integer getFibPosition(Long pos) {
        for (Integer i = 0; i <=fib.size(); i++) {
            if (fib.get(i) >= pos) {
                return i;
            }
        }
        return null;
    }
    public static void main(String[] args) {

        Scanner key = new Scanner(System.in);
        Integer ile = key.nextInt();
        List<Long> zad = new ArrayList<Long>();
        
        while((ile--)!=0) {
            zad.add(key.nextLong());
        }
       ilo f = new ilo();

        for(Long z : zad) {
                    System.out.println(f.canI(z));
                    
        }

    }

}