#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; vector sum(n + 1); rep(i, n) sum[i + 1] = sum[i] + a[i]; auto normalize = [&](ll y, ll m, ll d) { --y, --m, --d; ll res = 0; res += y * sum[n]; res += sum[m]; res += d; return res; }; auto to_date = [&](ll dd) { ll y = dd / sum[n]; dd %= sum[n]; int m = upper_bound(sum.begin(), sum.end(), dd) - sum.begin() - 1; int d = dd - sum[m]; return make_tuple(y + 1, m + 1, d + 1); }; int q; cin >> q; while (q--) { ll y, m, d, k; cin >> y >> m >> d >> k; // cerr << format("{}/{}/{}: {} {}\n", y, m, d, normalize(y, m, d), to_date(normalize(y, m, d))); auto [yy, mm, dd] = to_date(normalize(y, m, d) + k); cout << yy << ' ' << mm << ' ' << dd << '\n'; } return 0; }