#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);

int H, h, m, s;

//! x / y
class Frac{
public:
  using LL = long long;
  LL x, y;

  Frac(LL x = 0, LL y = 1) : x(x), y(y) { red(); }

  LL gcd(LL x, LL y){
	if(y == 0) return x;
	return gcd(y, x%y);
  }
  
  void red(){
	if(x == 0){
	  y = 1;
	  return;
	}
	if(y < 0){
	  x *= -1;
	  y *= -1;
	}
	
	LL g = gcd(abs(x), y);
	x /= g;
	y /= g;
  }

  Frac& operator += (const Frac& p){ x = x * p.y + y * p.x; y *= p.y; red(); return *this;}
  Frac operator + (const Frac& p) const{ Frac q = *this;return q += p;}
  Frac operator - () const { Frac q = *this; q.x *= -1; return q; }
  Frac& operator -= (const Frac& p){ Frac q = -p; *this += q; return *this;}
  Frac operator - (const Frac& p) const{ Frac q = *this; return q -= p;}
  Frac& operator *= (const Frac& a){ x *= a.x; y *= a.y; red(); return *this;}
  Frac operator * (Frac a) const{ Frac q = *this; return q *= a;}
  Frac& operator /= (const Frac& a){ x *= a.y; y *= a.x; red(); return *this;}
  Frac operator / (Frac a) const{ Frac q = *this; return q /= a;}

  bool operator < (const Frac &p) const{
	return x * p.y < y * p.x;
  }
  bool operator <= (const Frac &p) const{
	return *this < p || *this == p;
  }
  bool operator > (const Frac &p) const{
	return p < *this;
  }
  bool operator >= (const Frac &p) const{
	return *this > p || *this == p;
  }
  bool operator == (const Frac &p) const {
	return x == p.x && y == p.y;
  }
  double getR() const { return x * 1. / y; }
  friend ostream& operator <<(ostream& os, const Frac& p);
};
Frac abs(const Frac& q){ return Frac(abs(q.x), q.y); }
ostream& operator <<(ostream& os, const Frac& p){
  return os << p.x << "/" << p.y;
}

void norm(Frac& t){
  if(t.x < 0) t += 3600*H;
  while(t >= 60 * 60 * H)
	t -= 60 * 60 * H;
}

void normR(Frac& t){
  if(t.x < 0) t += 360;
  while(t >= 360)
	t -= 360;
}

Frac dist(Frac& now, Frac& dst){
  if(now <= dst) return dst - now;
  return dst + 3600*H - now;
}

void print(Frac& ans){
  LL ah = ans.x / ans.y / 60 / 60;
  LL am = ans.x / ans.y / 60 % 60;
  Frac as = ans - ah*3600 - am*60;
  cout << ah << " " << am << " " << as.x << " " << as.y << endl;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while(cin>>H>>h>>m>>s,H){
	Frac now(h*3600+m*60+s);
	
	Frac ans(1e9, 1), ans_dt(1e9, 1);
	REP(th,H) REP(tm,60){
	  for(int s1=-1;s1<=1;s1+=2){
		for(int s2=-1;s2<=1;s2+=2){
		  Frac c1(3600*th + 60*tm, 10*H);
		  Frac a1 = Frac(1, 10*H) - 6;
		  Frac c2(6*tm);
		  Frac a2 = Frac(1, 10) - 6;

		  for(int ang=0;ang<=360;ang+=360){
			Frac ss = (c2 * s2 - c1 * s1 + ang) / (a1 * s1 - a2 * s2);

			Frac rh = c1 + ss / (10*H);
			normR(rh);
			Frac rm = c2 + ss / 10;
			normR(rm);
			Frac rs = ss * 6;
			normR(rs);
			if(rh == rm || rh == rs || rm == rs) continue;
			Frac nxt = ss + 3600*th + 60*tm;
			norm(nxt);
			Frac dd = dist(now, nxt);
			if(dd < ans_dt){
			  ans_dt = dd;
			  ans = nxt;
			}
		  }
		}
	  }
	}
	print(ans);
  }

  return 0;
}

Measured memory_bytes: 3124