#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main() {
int M, X;
cin >> M >> X;
for (int page_size, page_num, record_count;
cin >> page_size >> page_num >> record_count;) {
int page, move;
if (page_size < M) {
page_size = M;
} else if (page_size > X)
page_size = X;
if (record_count % page_size != 0) {
page = (record_count / page_size) + 1;
} else
page = (record_count / page_size);
if (page_num < 1) {
page_num = 1;;
} else if (page_num > page && page != 0) {
page_num = page;
} else if (page == 0)
page_num = 1;
int64_t tmp = (int64_t)(page_num - 1) * (int64_t)page_size;
if ((int64_t) ((int32_t) tmp) != tmp) {
} else {
move = (page_num - 1) * page_size;
cout << page_size << " " << page << " " << page_num << " " << move << endl;
}
}
}