sigma = 26 # 遅延セグメント木 class lazy_segtree: def update(self, k): self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1]) def all_apply(self, k, f): self.d[k] = self.mapping(f, self.d[k]) if k < self.size: self.lz[k] = self.composition(f, self.lz[k]) def push(self, k): self.all_apply(2 * k, self.lz[k]) self.all_apply(2 * k + 1, self.lz[k]) self.lz[k] = self.identity def __init__(self, V, OP, E, MAPPING, COMPOSITION, ID): self.n = len(V) self.log = (self.n - 1).bit_length() self.size = 1 << self.log self.d = [E for i in range(2 * self.size)] self.lz = [ID for i in range(self.size)] self.e = E self.op = OP self.mapping = MAPPING self.composition = COMPOSITION self.identity = ID for i in range(self.n): self.d[self.size + i] = V[i] for i in range(self.size - 1, 0, -1): self.update(i) def set(self, p, x): assert 0 <= p and p < self.n p += self.size for i in range(self.log, 0, -1): self.push(p >> i) self.d[p] = x for i in range(1, self.log + 1): self.update(p >> i) def get(self, p): assert 0 <= p and p < self.n p += self.size for i in range(self.log, 0, -1): self.push(p >> i) return self.d[p] def prod(self, l, r): assert 0 <= l and l <= r and r <= self.n if l == r: return self.e l += self.size r += self.size for i in range(self.log, 0, -1): if ((l >> i) << i) != l: self.push(l >> i) if ((r >> i) << i) != r: self.push(r >> i) sml, smr = self.e, self.e while l < r: if l & 1: sml = self.op(sml, self.d[l]) l += 1 if r & 1: r -= 1 smr = self.op(self.d[r], smr) l >>= 1 r >>= 1 return self.op(sml, smr) def all_prod(self): return self.d[1] def apply_point(self, p, f): assert 0 <= p and p < self.n p += self.size for i in range(self.log, 0, -1): self.push(p >> i) self.d[p] = self.mapping(f, self.d[p]) for i in range(1, self.log + 1): self.update(p >> i) def apply(self, l, r, f): assert 0 <= l and l <= r and r <= self.n if l == r: return l += self.size r += self.size for i in range(self.log, 0, -1): if ((l >> i) << i) != l: self.push(l >> i) if ((r >> i) << i) != r: self.push((r - 1) >> i) l2, r2 = l, r while l < r: if l & 1: self.all_apply(l, f) l += 1 if r & 1: r -= 1 self.all_apply(r, f) l >>= 1 r >>= 1 l, r = l2, r2 for i in range(1, self.log + 1): if ((l >> i) << i) != l: self.update(l >> i) if ((r >> i) << i) != r: self.update((r - 1) >> i) def max_right(self, l, g): assert 0 <= l and l <= self.n assert g(self.e) if l == self.n: return self.n l += self.size for i in range(self.log, 0, -1): self.push(l >> i) sm = self.e while 1: while l % 2 == 0: l >>= 1 if not (g(self.op(sm, self.d[l]))): while l < self.size: self.push(l) l = 2 * l if g(self.op(sm, self.d[l])): sm = self.op(sm, self.d[l]) l += 1 return l - self.size sm = self.op(sm, self.d[l]) l += 1 if (l & -l) == l: break return self.n def min_left(self, r, g): assert 0 <= r and r <= self.n assert g(self.e) if r == 0: return 0 r += self.size for i in range(self.log, 0, -1): self.push((r - 1) >> i) sm = self.e while 1: r -= 1 while r > 1 and (r % 2): r >>= 1 if not (g(self.op(self.d[r], sm))): while r < self.size: self.push(r) r = 2 * r + 1 if g(self.op(self.d[r], sm)): sm = self.op(self.d[r], sm) r -= 1 return r + 1 - self.size sm = self.op(self.d[r], sm) if (r & -r) == r: break return 0 # Fenwick木 class fenwick_tree: n = 1 data = [0 for i in range(n)] def __init__(self, N): self.n = N self.data = [0 for i in range(N)] def add(self, p, x): assert 0 <= p < self.n, "0<=p 0: s += self.data[r - 1] r -= r & -r return s def op(x, y): if x is None or y is None: return None if x == sigma: return y if y == sigma: return x if x == y: return x else: return None e = sigma # ワイルドカード def mapping(f, x): if x is None: return None if x == sigma: return sigma return (x + f) % sigma def composition(f, g): return (f + g) % sigma id_ = 0 S = input() T = input() diff = [] for s, t in zip(S, T): diff.append((ord(s) - ord(t)) % sigma) seg = lazy_segtree(diff, op, e, mapping, composition, id_) s_imos = fenwick_tree(len(S) + 1) t_imos = fenwick_tree(len(T) + 1) Q = int(input()) for _ in range(Q): cmd, *query = list(map(int, input().split())) if cmd == 1: l, r, x = query seg.apply(min(l - 1, len(S), len(T)), min(r, len(S), len(T)), x) s_imos.add(l - 1, x) s_imos.add(r, -x) elif cmd == 2: l, r, x = query seg.apply(min(l - 1, len(S), len(T)), min(r, len(S), len(T)), -x % sigma) t_imos.add(l - 1, x) t_imos.add(r, -x) else: p = query[0] idx = seg.max_right(p - 1, lambda x: x == 0 or x == sigma) if idx < min(len(S), len(T)): s = (s_imos.sum(0, idx + 1) + ord(S[idx]) - ord("a")) % sigma t = (t_imos.sum(0, idx + 1) + ord(T[idx]) - ord("a")) % sigma if s > t: print("Greater") elif s < t: print("Lesser") else: if len(S) > len(T): print("Greater") elif len(S) < len(T): print("Lesser") else: print("Equals")