#include<bits/stdc++.h>
using namespace std;
int t,m,a,b,c;
bool judge(double n)
{
int m=int(n);
if(n==m)
{
return 1;
}
return 0;
}
int factor(int n)
{
for(int i=sqrt(n);i>=2;i--)
{
if(n%(i*i)==0)
{
return i;
}
}
return 1;
}
int main()
{
cin>>t>>m;
for(int i=1;i<=t;i++)
{
cin>>a>>b>>c;
if(a<0)
{
a=-a;
b=-b;
c=-c;
}
if(b*b-4*a*c<0)
{
cout<<"NO"<<endl;
continue;
}
else
{
int z=b*b-4*a*c;
double x=(b*(-1)+sqrt(z))/(2*a);
if(judge(sqrt(z))==1)
{
if(judge(x)==1)
{
if(x==-0)
{
cout<<0<<endl;
}
else
{
cout<<x<<endl;
}
}
else
{
int n=-b+sqrt(z);
int m=2*a;
cout<<n/abs(__gcd(n,m))<<"/"<<m/abs(__gcd(n,m))<<endl;
}
}
else
{
double q1=(b*1.0/(2*a))*-1;
double q2=1/(2*a);
int d=factor(z);
if(q1==-0)
{
q1=0;
}
if(q1!=0)
{
if(judge(q1)==1)
{
cout<<q1;
}
else
{
int n=(b*1.0)*-1;
int m=2*a;
cout<<n/abs(__gcd(n,m))<<"/"<<m/abs(__gcd(n,m));
}
cout<<"+";
}
if(q2==1)
{
cout<<sqrt(z)<<endl;
}
else if(judge(q2)==1)
{
double s=d*1.0/(2*a);
if(judge(s)==1)
{
cout<<s<<"*"<<"sqrt("<<z/(d*d)<<")"<<endl;
}
else
{
if(__gcd(d,2*a)==1)
{
if(d!=1)
{
cout<<d<<"*";
}
cout<<"sqrt("<<z/(d*d)<<")"<<"/"<<2*a<<endl;
}
else
{
cout<<"sqrt("<<z/(d*d)<<")/"<<2*a/__gcd(d,2*a)<<endl;
}
}
}
}
}
}
return 0;
}