class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.q: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: B = None
        self.o: B = None
        self.txt = txt

g = A("g")
a = B("a")
l = A("l")
b = B("b")
m = A("m")
e = A("e")
d = B("d")

g.t = e
g.q = e
a.s = b
a.o = b
l.t = e
l.q = m
b.s = a
b.o = d
m.t = l
m.q = g
e.t = m
e.q = l
d.s = b
d.o = b
assert d.o.o.s.s.s.s.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.q: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: B = None
        self.o: B = None
        self.txt = txt

g = A("g")
a = B("a")
l = A("l")
b = B("b")
m = A("m")
e = A("e")
d = B("d")

g.t = e
g.q = e
a.s = b
a.o = b
l.t = e
l.q = m
b.s = a
b.o = d
m.t = l
m.q = g
e.t = m
e.q = l
d.s = b
d.o = b
assert d.o.o.s.s.s.s.o.txt == "b"