#include <iostream>
#include <cstdio>
#include <algorithm>
#define P printf
#define S scanf
using namespace std;
struct times
{
    int h,m,s;
};
times t1,t2;
int g,g1,g2,m,s,s1,s2;
void next_second (times &t)
{
    t.s++;
    if (t.s==60)
    {
        t.s=0;
        t.m++;
    }
    if (t.m==60)
    {
        t.m=0;
        t.h++;
    }
    if (t.h==12)
        t.h=0;
}
int abs (int x)
{
    if (x<0)
        return -x;
    else
        return x;
}
int main ()
{
    S("%d%d%d",&t1.h, &t1.m, &t1.s);
    S("%d%d%d",&t2.h, &t2.m, &t2.s);
    S("%d%d",&m,&g);
    g+=m*60;
    for (;;)
    {
        g1=t1.h*1800 + t1.m*30;
        s1=g1*60+t1.s*30;
        g2=t1.m*360 + t1.s*6;
        s2=g2*60;
        if (min(abs(s2-s1),360*3600-abs(s2-s1))<=g*60)
            s++;
        if (t1.h==t2.h && t1.m==t2.m && t1.s==t2.s)
            break;
        next_second(t1);
    }
    P("%d ",s/60);
    s=s%60;
    P("%d\n",s);
    return 0;
}
