#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int gcd(int a, int b)
{
if (a % b==0) return b;
else return gcd(b, a % b);
}//շת���������
class FS
{
private:
int fz,fm;
public:
friend int gcd(int a,int b);
void set(int newfz,int newfm)
{
fz=newfz;fm=newfm;
}
FS operator + (const FS &f)
{
fz=fz*f.fm+f.fz*fm;
fm=f.fm*fm;
int t=gcd(fz,fm);
fz=fz/t;fm=fm/t;
if(fm<0){fm=-fm;fz=-fz;}
FS f_new;
f_new.set(fz,fm);
return f_new;
}
void display()
{
cout<<fz<<"z"<<fm<<"m"<<endl;
}
};
int main()
{
int n;
cin>>n;
int i;
for(i=1;i<=n;i++)
{
FS fs1,fs2,fs3;
int z,m;
char z1,m1;
cin>>z>>z1>>m>>m1;
fs1.set(z,m);
cin>>z>>z1>>m>>m1;
fs2.set(z,m);
fs3=fs1+fs2;
fs3.display();
}
return 0;
}
#include<iostream>
using namespace std;
class Time
{
private:
int hour;
int minute;
public:
Time(){}
Time(int h,int m):hour(h),minute(m){}
void set(int h, int m)
{
hour = h;
minute = m;
}
int operator-(const Time& t)
{
return hour * 60 + minute - t.hour * 60 - t.minute;
}
};
int main()
{
int a, b, c, d;
while (1)
{
Time t1, t2;
cin >> a >> b >> c >> d;
if (a == 00 && b == 00 && c == 00 && d == 00) break;
t1.set(a, b);
t2.set(c, d);
int res = t2 - t1;
cout << res << endl;
}
}