n = int(input()) assert 1 <= n <= 10 ** 5 alp = [chr(i+97) for i in range(26)] d = dict() for _ in range(n): x, l, r = map(str, input().split()) l = int(l) r = int(r) assert 1 <= len(x) <= 5 for c in x: assert c in alp assert 1 <= l <= 10 ** 9 assert 1 <= r <= 10 ** 9 assert l <= r if x not in d: d[x] = dict() d[x][l-0.1] = 0 d[x][r+0.1] = 1 q = int(input()) for _ in range(q): qr = list(map(str, input().split())) qr[0] = int(qr[0]) if qr[0] == 1: x, t = qr[1:] assert 1 <= len(x) <= 5 for c in x: assert c in alp t = int(t) assert 1 <= t <= 10 ** 9 elif qr[0] == 2: t = int(qr[1]) assert 1 <= t <= 10 ** 9 elif qr[0] == 3: x, l, r = qr[1:] l = int(l) r = int(r) assert 1 <= len(x) <= 5 for c in x: assert c in alp assert 1 <= l <= 10 ** 9 assert 1 <= r <= 10 ** 9 assert l <= r if x not in d: d[x] = dict() d[x][l-0.1] = 0 d[x][r+0.1] = 1 for x in d.keys(): prev = 1 for t in sorted(d[x].keys()): assert d[x][t] ^ prev prev = d[x][t]