#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>
#include <sstream>

int64_t N, L;
char direc[100][10];
int64_t posion[100];
int64_t posionnow[201];
int64_t H, h, m, s;
std::stringstream sssss;

int64_t gcd(int64_t a, int64_t b)
{
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

void solve() {

	const int64_t MULMUL = 20 * H * 360;
	//int64_t hdeg = 2 * h;
	//int64_t mdeg = 2 * H * m;
	//int64_t sdeg = 20 * H * 6 * s;
	int64_t hdeg = 20 * 360 * h + 2 * 60 * m + 2 * s;
	int64_t mdeg = 20 * H * 6 * m + 2 * H * s;
	int64_t sdeg = 20 * H * 6 * s;

	int64_t rotate_sum = 0;
	while (true)
	{

		sdeg -= hdeg;
		if (sdeg < 0) {
			sdeg += MULMUL;
		}
		mdeg -= hdeg;
		if (mdeg < 0) {
			mdeg += MULMUL;
		}
		rotate_sum += hdeg;
		hdeg = 0;

		int64_t mid1 = mdeg / 2;
		int64_t mid2 = mid1 + MULMUL / 2;
		int64_t mid = mid1;
		int64_t midsend = mid2;
		if (mid1 < sdeg && sdeg <= mid2) {
			mid = mid2;
			midsend = mid1;
		}

		if (mid < sdeg) {
			mid += MULMUL;
		}
		if (midsend < sdeg) {
			midsend += MULMUL;
		}
		int64_t timedown = (20 * H * 6 - (H + 1));
		int64_t time20H = (mid - sdeg);
		if ((mdeg* timedown + 2 * H * time20H)% (MULMUL* timedown) == (2 * time20H) % (MULMUL * timedown)){

			timedown = (20 * H * 6 - (H + 1));
			time20H = (midsend - sdeg);
			if ((mdeg * timedown + 2 * H * time20H) % (MULMUL * timedown) == (2 * time20H) % (MULMUL * timedown)) {
				assert(false);
			}
		}

		hdeg += 2 * time20H / timedown;
		hdeg += rotate_sum; hdeg %= MULMUL;
		mdeg += 2 * H * time20H / timedown;
		mdeg += rotate_sum; mdeg %= MULMUL;
		sdeg += rotate_sum; sdeg %= MULMUL;

		using namespace std;
		//assert(hdeg % (20 * 360) == 0);
		//assert(mdeg % (20 * H * 6) == 0);
		int64_t sup = (sdeg * timedown + 6*20*H* time20H) % (MULMUL * timedown);
		int64_t sdown = 20 * H * 6 * timedown;
		int64_t ggg = gcd(sup, sdown);

		sssss
			<< hdeg / (20 * 360) << ' '
			<< mdeg / (20 * H * 6) << ' '
			<< sup / ggg		 << ' '
			<< sdown / ggg		
			<< '\n';

		break;
	}
}
int main()
{
	using namespace std;

	while (true)
	{
		cin >> H >> h >> m >> s;

		if (H == 0 && h == 0 && m == 0 && s == 0) {
			break;
		}
		solve();
	}
	cout << sssss.str();
	return 0;

}
