#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;



int x;
int y;

int f(int a , int b , int c );
void solve();

int main()
    {
    solve();
    return 0;
    }


void solve()
    {
    int a ,b ,c ,a1 ,b1 ,c1;
    int br=0;
    scanf("%d%d%d",&a,&b,&c);
    scanf("%d%d%d",&a1,&b1,&c1);
    scanf("%d%d",&x,&y);
    x=60*x+y;
    x=x*2;
    while(a!=a1 || b!=b1 || c!=c1)
        {
        if(f(a,b,c)==1)br++;
        c++;
        if(c==60)
            {
            b++;
            c=0;
            if(b==60)
                {
                a++;
                b=0;
                if(a==12)a=0;
                }
            }
        }
    if(f(a,b,c)==1)br++;
    printf("%d %d\n",br/60,br%60);
    }


int f(int a , int b , int c )
    {
    int p1=3600*a+60*b+c;
    int p2=720*b+12*c;
    if(abs(p1-p2)<=x)return 1;
    return 0;
    }
