#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <cctype>
using namespace std;
char s1[800], s2[800];
int num[2][5];
int gcd(int a, int b)
{
if (a < b) swap(a, b);
while (b) {
int tmp = a % b; a = b; b = tmp;
}
return a;
}
int cal(char *s, int xx, int f, int ff)
{
int t = 0, k = 1, x = xx;
bool flag = 0;
if (x == f - 1) return 1;
while (x >= f && isdigit(s[x])) {
if (isdigit(s[x])) flag = 1;
t += k * (s[x] - '0'), k *= 10; x--;
}
if (t == 0 && ff && !flag) t = 1;
while (x >= f && (s[x] == '+' || s[x] == '-')) {
if (s[x] == '-') t *= -1; x--;
}
return t;
}
void change(char *s)
{
int cnt = 0, len = strlen(s);
for (int i = 0; i < len; i++)
if (s[i] != ' ') s[cnt++] = s[i];
for (int i = cnt; i < len; i++)
s[i] = '\0';
}
void make(char *s, int line)
{
int len = strlen(s), pos;
for (int i = 0; i < len; i++) {
if (s[i] == '+' || s[i] == '-' || s[i] == '='){
int j = i - 1;
if (s[j] == 'x')
num[line][0] += cal(s, j - 1, 0, 1);
else if (s[j] == 'y')
num[line][1] += cal(s, j - 1, 0, 1);
else if (isdigit(s[j]))
num[line][2] -= cal(s, j, 0, 0);
}
if (s[i] == '=') { pos = i + 1; break; }
}
for (int i = pos; i <= len; i++){
if (s[i] == '+' || s[i] == '-' || i == len) {
int j = i - 1;
if (s[j] == 'x')
num[line][0] -= cal(s, j - 1, pos, 1);
else if (s[j] == 'y')
num[line][1] -= cal(s, j - 1, pos, 1);
else if (isdigit(s[j]))
num[line][2] += cal(s, j, pos, 0);
}
}
}
void impos(){printf("don't know\n");}
void print(int x, int y, int z)
{
if (z != 0) impos();
else if (y == 0) printf("0\n");
else {
int ttt = gcd(abs(x), abs(y));
if (x * y < 0 && abs(x) != ttt) printf("-%d/%d\n", abs(y)/ttt, abs(x)/ttt);
else if (x * y < 0 && abs(x) == ttt) printf("-%d\n", abs(y)/ttt);
else if (x * y > 0 && abs(x) != ttt) printf("%d/%d\n", abs(y)/ttt, abs(x)/ttt);
else printf("%d\n", abs(y)/ttt);
}
}
void solve()
{
int a, b, c, aa, bb, cc;
a = num[0][0]; b = num[0][1]; c = num[0][2]; aa = num[1][0]; bb = num[1][1]; cc = num[1][2];
if ((!a && !b && !aa && !bb)||(!a && !b && aa && bb)||(a && b && !aa && !bb))
impos(), impos();
else if (a && !b && !aa && !bb) print(a, c, cc), impos();
else if (!a && b && !aa && !bb) impos(), print(b, c, cc);
else if (!a && !b && aa && !bb) print(aa, cc, c), impos();
else if (!a && !b && !aa && bb) impos(), print(bb, cc, c);
else if (a && !b && aa && !bb) {
if (a * cc == aa * c) print(a, c, 0), impos();
else impos(), impos();
}
else if (!a && b && !aa && bb) {
if (b * cc == bb * c) impos(), print(b, c, 0);
else impos(), impos();
}
else if (a && !b && !aa && bb) print(a, c, 0), print(bb, cc, 0);
else if (!a && b && aa && !bb) print(b, c, 0), print(aa, cc, 0);
else if (!a && b && aa && bb) print(aa * b, cc * b - c * bb, 0), print(b, c, 0);
else if (a && !b && aa && bb) print(a, c, 0), print(bb * a, cc * a - c * aa, 0);
else if (a && b && !aa && bb) print(a * bb, c * bb - cc * b, 0), print(bb, cc, 0);
else if (a && b && aa && !bb) print(aa, cc, 0), print(b * aa, c * aa - cc * a, 0);
else{
if (a * bb == b * aa) impos(), impos();
else print(a * bb - aa * b, c * bb - cc * b, 0), print(b * aa - bb * a, c * aa - cc * a, 0);
}
}
int main()
{
int cas, flag, count = 0;
cin >> cas;
while (cas--)
{
getchar();
gets(s1); gets(s2);
memset(num, 0, sizeof(num));
change(s1), change(s2);
make(s1, 0); make(s2, 1);
solve();
if (cas) printf("\n");
}
return 0;
}