import bisect,sys input = sys.stdin.readline n = int(input()) a = list(map(int,input().split())) q = int(input()) b = [0 for i in range(n+1)] for i in range(n): b[i+1] = b[i] + a[i] s = sum(a) for i in range(q): y,m,d,k = map(int,input().split()) x = s * (y-1) + b[m-1] + d-1 x += k y = x // s x %= s m = max(0,bisect.bisect_left(b,x)-1) x -= b[m] y = y+1 m = m+1 d = x+1 if d > a[m-1]: d -= a[m-1] m += 1 if m == n: m = 1 n += 1 print(y,m,d)