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

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

i = A("i")
d = B("d")
l = A("l")
h = A("h")
a = A("a")
m = B("m")
c = B("c")

i.s = m
i.t = m
d.q = m
l.s = m
l.t = m
h.s = m
h.t = d
a.s = c
a.t = d
m.q = c
c.q = m
assert h.s.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.t: B = None
        self.txt = txt

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

i = A("i")
d = B("d")
l = A("l")
h = A("h")
a = A("a")
m = B("m")
c = B("c")

i.s = m
i.t = m
d.q = m
l.s = m
l.t = m
h.s = m
h.t = d
a.s = c
a.t = d
m.q = c
c.q = m
assert h.s.q.q.q.txt == "c"