#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=(l);i<(r);i++)
#define int long long
using namespace std;
int gcd(int a, int b)
{
a = abs(a), b = abs(b);
if (a < b)
swap(a, b);
if (!b)
return a;
return gcd(b, a % b);
}
bool pd(int a)
{
int d = sqrt(a);
return d * d == a;
}
bool pd2(int a, int b)
{
int d = gcd(a, b);
return d == b or b == 1;
}
void yf(int &ansx, int &ansy)
{
int g = gcd(ansx, ansy);
ansx /= g, ansy /= g;
}
struct node
{
int x, y;
node operator +(node t)
{
node ans;
ans.x = x * t.y + y * t.x;
ans.y = y * t.y;
yf(ans.x, ans.y);
return ans;
}
node operator /(node t)
{
node ans;
ans.x = x * t.y;
ans.y = y * t.x;
yf(ans.x, ans.y);
return ans;
}
};
void yf(node &ans)
{
int g = gcd(ans.x, ans.y);
ans.x /= g, ans.y /= g;
if (ans.y < 0)
ans.y = -ans.y, ans.x = -ans.x;
}
int yf(int &x)
{
int i = 2, c = x, ans = 1;
while (c != 1)
{
if (c % i == 0)
{
int cnt = 0;
while (c % i == 0) c /= i, cnt++;
ans *= pow(i, cnt >> 1);
}
i++;
}
x /= ans * ans;
return ans;
}
signed main()
{
int T, M;
cin >> T >> M;
while (T--)
{
node a, b, c;
scanf("%lld%lld%lld", &a.x, &b.x, &c.x);
a.y = b.y = c.y = 1;
if (b.x * b.x < 4 * a.x * c.x)
{
printf("NO\n");
continue;
}
int d = b.x * b.x - 4 * a.x * c.x;
if (pd(d))
{
int q1 = sqrt(d) - b.x;
if (pd2(q1, 2 * a.x))
printf("%lld\n", q1 / 2 / a.x);
else
{
int ansx = q1, ansy = a.x * 2;
yf(ansx, ansy);
printf("%lld/%lld\n", ansx, ansy);
}
}
else
{
node q = {-b.x, 2 * a.x};
yf(q);
if (q.x != 0)
{
if (q.y == 1)
printf("%lld+", q.x);
else
printf("%lld/%lld+", q.x, q.y);
}
int t = yf(d), q2 = a.x * 2;
yf(t, q2);
if (t != 1)
printf("%lld*", t);
printf("sqrt(%lld)", d);
if (q2 != 1)
printf("/%lld", q2);
printf("\n");
}
}
return 0;
}