import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;

string format(F S) {
    F r = S % 3600;
    F h = (S - r) * f(1, 3600); S = r; r = S % 60;
    F m = (S - r) * f(1, 60); S = r; 
    F s = r;
    h.reduce; m.reduce; s.reduce;
    return text(h.longeger, " ", m.longeger, " ", s.toString.split("/").join(" "));
}

template lcm(T) {
    T lcm(T a, T b) {
        return a / gcd(a.abs, b.abs) * b;
    }
}

class F {
    long a, b; // a / b;
    this(long a, long b) {
        if (b < 0) { a = -a; b = -b; }
        this.a = a;
        this.b = b;
        reduce;
    }
    void reduce() {
        long g = gcd(a.abs, b.abs);
        a /= g;
        b /= g;
    }
    F dup() {
        return new F(a, b);
    }
    override string toString() {
        return text(a, "/", b);
    }
    F opUnary(string op)() if (op == "-") {
        return new F(-a, b);
    }
    F opBinary(string op)(F rhs) if (op == "+") {
        F ret = this.dup;
        long l = lcm(b, rhs.b);
        ret.b = l;
        ret.a = a * (l / b) + rhs.a * (l / rhs.b);
        ret.reduce;
        return ret;
    }
    F opBinary(string op)(long rhs) if (op == "+") {
        return this + new F(rhs, 1);
    }
    F opBinary(string op)(F rhs) if (op == "-") {
        return this + (-rhs);
    }
    F opBinary(string op)(long rhs) if (op == "-") {
        return this + (-rhs);
    }
    F opBinary(string op)(F rhs) if (op == "*") {
        F ret = this.dup;
        ret.a *= rhs.a;
        ret.b *= rhs.b;
        ret.reduce;
        return ret;
    }
    F opBinary(string op)(long rhs) if (op == "*") {
        F ret = this.dup;
        ret.a *= rhs;
        ret.reduce;
        return ret;
    }
    F opBinary(string op)(F rhs) if (op == "/") {
        return this * (new F(rhs.b, rhs.a));
    }
    override bool opEquals(Object o) {
        F rhs = cast(F)o;
        return a == rhs.a && b == rhs.b;
    }
    override int opCmp(Object o) {
        F rhs = cast(F)o;
        long l = lcm(b, rhs.b);
        long x = a * (l / b),
            y = rhs.a * (l / rhs.b);
        return cast(int)( (x - y) / abs(x - y) );
    }
    long longeger() {
        return a / b;
    }
    F frac() {
        return this - a / b;
    }
    F opBinary(string op)(long M) if (op == "%") {
        return frac + (longeger % M);
    }
}

F f(long a, long b) {
    return new F(a, b);
}

void main() {
    long H, h, m, s;
    while (readf("%d %d %d %d\n", &H, &h, &m, &s), H || h || m || s) {
        long S = h * 3600 + m * 60 + s;
        F vsec = f(6, 1);
        F vmin = f(1, 10);
        F vhour = f(1, 10 * H);
        F vmid = (vmin + vhour) * f(1, 2);
        F pmid = (vmid * S) % 360;
        F psec = (vsec * S) % 360;
        F dist = min((pmid + 360 - psec) % 360, (pmid + 540 - psec) % 360);
        //[dist, vsec, vmid].writeln;
        F cand = dist / (vsec - vmid) + S;
        //writeln("vars: ", [dist, vsec, vmid, vsec - vmid]);
        //writeln("cand: ", cand);
        cand = cand % (H * 3600);
        if (vsec * cand % 360 == vmin * cand % 360 &&
                vmin * cand % 360 == vhour * cand % 360) {
            cand = cand + f(180, 1) / (vsec - vmid);
        }
        cand = cand % (H * 3600);
        //[vsec * cand % 360, vmin * cand % 360, vhour * cand % 360].writeln;
        //cand.writeln;
        format(cand).writeln;
        //vmid.writeln;
    }
} 

Measured memory_bytes: 1500