from collections import defaultdict from heapq import heappush, heappop HC = defaultdict(int) H = [] def hpush(x): heappush(H, -x) HC[x] += 1 def hpop(): t = -heappop(H) while not HC[t]: t = -heappop(H) HC[t] -= 1 return t def hmax(): a = hpop() hpush(a) return a def hdel(x): assert HC[x] > 0 HC[x] -= 1 N, M = map(int, input().split()) A = [int(a) for a in input().split()] for i, a in enumerate(A): hpush(a * M + i) Q = int(input()) for _ in range(Q): t, x, y = map(int, input().split()) x -= 1 if t == 1: hdel(A[x] * M + x) A[x] += y hpush(A[x] * M + x) elif t == 2: hdel(A[x] * M + x) A[x] -= y hpush(A[x] * M + x) else: print(hmax() % M + 1)