Payton numbers

All submissions for this problem are available.
Payton likes numbers, but all the numbers he has ever known are the ordinary integers, and he doesn't like it. Thus he created his own set of “numbers”, which he called Payton numbers.
Each Payton number is a triplet of ordinary integers (a,b,c), with the restriction that c is either 11 or 24 (because Payton likes 11 and 24). And then, Payton defines the product of two Payton numbers (a_{1},b_{1},c_{1}) and (a_{2},b_{2},c_{2}) as the following:
def multiply((a_{1},b_{1},c_{1}), (a_{2},b_{2},c_{2})):
s = (a_{1}a_{2} + b_{1}b_{2} + c_{1}c_{2}) + (a_{1}b_{2} + b_{1}a_{2}) + (c_{1} + c_{2})
t = floor[s/2] + 16(c_{1} + c_{2})  c_{1}c_{2}
A = (t  2(a_{1}b_{2} + b_{1}a_{2})  (a_{1}c_{2} + c_{1}a_{2}) + 33(a_{1} + a_{2})
+ (b_{1}b_{2}  a_{1}a_{2}))
B = (t  5(a_{1}b_{2} + b_{1}a_{2})  (c_{1}b_{2} + b_{1}c_{2}) + 33(b_{1} + b_{2})
+ (2b_{1}b_{2} + 4a_{1}a_{2}))
if s is even:
return (A540,B540,24)
else:
return (A533,B533,11)
Eventually, Payton found out that he can define many interesting things about his numbers:
A zero is a Payton number z whose product with any other Payton number is z. Payton proved that there is a unique zero in Payton numbers, namely (11,11,11).
A unity is a Payton number whose product with any other Payton number is that Payton number. Payton proved that there is a unique unity in Payton numbers, namely (4,4,24).
A Payton number x divides another Payton number y if there exists a Payton number z such that x·z = y.
A Payton number is a unit if it divides a unity. Payton proved that any unity is also a unit, therefore (4,4,24) is a unit. But it's possible that there are other units.
A Payton number is prime if it isn't a zero, isn't a unit, and can't be written as the product of two nonzero, nonunit Payton numbers.
Given a Payton number, Payton wants to determine whether it is prime or not. Please help him, so that he can start replacing all numbers in math with Payton numbers!
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
Each test case consists of one line which contains three integers, a, b and c, representing the Payton number (a,b,c).
Output
For each test case, output a single line containing a word: “PRIME” if the Payton number is a prime, and “NOT PRIME” otherwise.
Constraints
 1 ≤ T ≤ 10^{4}
 c is either 11 or 24
Subtasks
 Subtask #1: (30 points) 10^{4} ≤ a, b ≤ 10^{4}
 Subtask #2: (70 points) 10^{7} ≤ a, b ≤ 10^{7}
Example
Input:4 11 11 11 4 4 24 104 126 11 4 5 24
Output:NOT PRIME NOT PRIME NOT PRIME PRIME
Explanation
Example case 1. The number (11,11,11) is a zero, so it's not prime.
Example case 2. The number (4,4,24) is a unit, so it's not prime.
Example case 3. The number (104,126,11) is not a prime, since it is the product of two nonzero nonunits (13,26,24) and (4,8,11).
Example case 4. It can be shown that the number (4,5,24) isn't a zero, isn't a unit, and cannot be factored into two nonzero nonunits. Therefore it is prime.
Author:  kevinsogo 
Tester:  pushkarmishra 
Editorial  http://discuss.codechef.com/problems/CUSTPRIM 
Tags  advancedmath, feb15, hard, kevinsogo 
Date Added:  5122014 
Time Limit:  5 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 