#include<bits/stdc++.h>
#define int long long
#define double long double
#define R(x) x=read()
#define abs(x) ((x)>=0?(x):-(x))
#define pushq(x) push('s');push('q');push('r');push('t');push('(');write(x);push(')');
using namespace std;
inline int read(){
register int r=0,f=1;register char c=getchar();
while(!isdigit(c)){
if(c=='-')f=-1;
c=getchar();
}
while(isdigit(c)){
r=(r<<3)+(r<<1)+(c^48);
c=getchar();
}
return r*f;
}
char obuf[1<<21],*pp=obuf;
void push(char c){
if(pp-obuf==1<<21)fwrite(obuf,1,pp-obuf,stdout),pp=obuf;
*pp++ = c;
}
class O{public:~O(){fwrite(obuf,1,pp-obuf,stdout);}}_;
inline void write(int x){
static int _t_[64]={},len=0;
if(x<0){push('-');x=-x;}
while(x||!len){_t_[++len]=x%10;x/=10;}
while(len)push(48^_t_[len--]);
}
void w(int p,int q){//p/q
bool f=(p*q>=0);//解是否非负
if(!f)push('-');
p=abs(p);q=abs(q);
int g=__gcd(p,q);
p/=g;q/=g;
write(p);
if(q!=1){
push('/');
write(q);
}
}
void w2(int q1,int q2,int r,int p){
if(q1){
w(q1,p);
push('+');
}
q2=abs(q2);p=abs(p);
int g=__gcd(q2,p);
q2/=g;p/=g;
if(q2==p){
pushq(r);
}else if(p==1){
write(q2);
push('*');
pushq(r);
}else if(q2==1){
pushq(r);
push('/');
write(p);
}else{
write(q2);
push('*');
pushq(r);
push('/');
write(p);
}
}
int t,M;
int a,b,c,del;
signed main(){
//#ifndef LOCAL
// freopen("uqe.in","r",stdin);
// freopen("uqe.out","w",stdout);
//#endif
R(t);R(M);
while(t--){
R(a);R(b);R(c);
del=b*b-4*a*c;
if(del<0){
push('N');
push('O');
}else{
double d=sqrt(del),d2=del*1.0;
d=d*d;
if(d==d2){//有理数
int q=2*a,p=-b;
// cerr << 'p' << endl;
//取到较大的根
if( (p+sqrt(del))/q > (p-sqrt(del))/q ){
p+=sqrt(del);
}else{
p-=sqrt(del);
}
// cerr << p << " " << q << endl;
if(p==0){
write(0);
}else w(p,q);
}else{//无理数
int q1=-b,r=del,q2=1,p=2*a;
for(int i=2;i*i<=r;i++){
while(r%(i*i)==0){
r/=(i*i);
q2*=i;
}
}
w2(q1,q2,r,p);
}
}
push('\n');
}
return 0;
}
/*
1 1121
6 0 0
*/
洛谷上 WA 了第四个点,图灵上第八个