#include<iostream>
using namespace std;
class FS {
private:
int fz;
int fm;
public:
FS() {}
FS(int a, int b) {
fz = a;
fm = b;
}
FS operator+(const FS& f) {
int m, i,n;
m = this->fm * f.fm;
n = this->fz * f.fm + f.fz * this->fm;
for (i = 2; i < n; i++) {
if (n % i == 0 && m % i == 0) {
m /= i;
n /= i;
}
}
return FS(n, m);
}
void setnumber(int a, int c) {
fz = a;
fm = c;
}
~FS() {}
void show() {
if (fm < 0) {
fm = -1 * fm;
fz = -1 * fz;
cout << fz << "z" << fm << "m" << endl;
}
else {
cout << fz << "z" << fm << "m" << endl;
}
}
};
int main() {
int n;
cin >> n;
while (n - 1 != 0) {
FS f1, f2, f3;
int fz1, fm1, fz2, fm2;
char a, b;
cin >> fz1 >> a >> fm1 >> b;
f1.setnumber(fz1, fm1);
cin >> fz2 >> a >> fm2 >> b;
f2.setnumber(fz2, fm2);
f3 = f1 + f2;
f3.show();
n-=1;
}
return 0;
}
#include<iostream>
using namespace std;
class Time
{
private:
int t_hour;
int t_min;
public:
void set(int h, int m)
{
t_min = m;
t_hour = h;
}
friend int operator -(Time ,Time);
};
int operator-(Time t2, Time t1) {
return (t2.t_hour - t1.t_hour) * 60 + t2.t_min - t1.t_min;
}
int main()
{
int a, b, c, d;
Time t1, t2;
cin >> a >> b >> c >> d;
do {
t1.set(a,b);
t2.set(c,d);
cout<<(t2-t1)<<endl;
cin >> a >> b >> c >> d;
} while (!(a == 0 && b == 0 && c == 0 && d == 0));
}