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.integer, " ", m.integer, " ", s.toString.split("/").join(" "));
}

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

class F {
    int a, b; // a / b;
    this(int a, int b) {
        this.a = a;
        this.b = b;
        reduce;
    }
    void reduce() {
        int 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;
        int 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)(int rhs) if (op == "+") {
        return this + new F(rhs, 1);
    }
    F opBinary(string op)(F rhs) if (op == "-") {
        return this + (-rhs);
    }
    F opBinary(string op)(int 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)(int 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;
        int l = lcm(b, rhs.b);
        int x = a * (l / b),
            y = rhs.a * (l / rhs.b);
        return x - y;
    }
    int integer() {
        return a / b;
    }
    F frac() {
        return this - a / b;
    }
    F opBinary(string op)(int M) if (op == "%") {
        return frac + (integer % M);
    }
}

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

void main() {
    int H, h, m, s;
    while (readf("%d %d %d %d\n", &H, &h, &m, &s), H || h || m || s) {
        int 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;
        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;
    }
} 