#include<bits/stdc++.h>
using namespace std;
int t,m,a,b,c;
inline int mysqrt(int n){
int res=1;
for(int i=2;i*i<=n;i++){
while(n%(i*i)==0){
res*=i;
n/=(i*i);
}
}
return res;
}
int main(){
scanf("%d%d",&t,&m);
while(t--){
scanf("%d%d%d",&a,&b,&c);
int temp=b*b-4*a*c;
if(temp<0){
puts("NO");
continue;
}
if(temp==0){
int q1=-b,q2=2*a;
temp=__gcd(q1,q2);
q1/=temp,q2/=temp;
if(q2<0){
q1=-q1;
q2=-q2;
}
if(q2!=1) printf("%d/%d\n",q1,q2);
else printf("%d\n",q1);
continue;
}
int res=mysqrt(temp);
if(res*res==temp){
int q1=-b+res,q2=2*a;
temp=__gcd(q1,q2);
q1/=temp,q2/=temp;
if(q2<0){
q1=-q1;
q2=-q2;
}
int p1=-b-res,p2=2*a;
temp=__gcd(p1,p2);
p1/=temp,p2/=temp;
if(p2<0){
p1=-p1;
p2=-p2;
}
if(p1>q1){
q1=p1;
q2=p2;
}
if(q2!=1&&q1!=0) printf("%d/%d\n",q1,q2);
else printf("%d\n",q1);
continue;
}
int q1=-b,q2=2*a;
int k=__gcd(q1,q2);
q1/=k,q2/=k,temp/=(res*res);
if(q2<0){
q1=-q1;
q2=-q2;
}
if(q1!=0){
if(q2!=1) printf("%d/%d+",q1,q2);
else printf("%d+",q1);
}
q2=2*a;
k=abs(__gcd(res,q2));
res/=k,q2/=k;
if(res<0) res=-res;
if(q2<0) q2=-q2;
if(res!=1) printf("%d*",res);
if(q2!=1) printf("sqrt(%d)/%d\n",temp,q2);
else printf("sqrt(%d)\n",temp);
}
return 0;
}