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

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

d = A("d")
i = B("i")
c = B("c")
f = A("f")
h = A("h")
b = B("b")
e = B("e")
a = A("a")

d.t = i
d.o = c
i.s = h
c.s = d
f.t = b
f.o = b
h.t = b
h.o = b
b.s = d
e.s = a
a.t = c
a.o = e
assert b.s.o.s.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.o: B = None
        self.txt = txt

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

d = A("d")
i = B("i")
c = B("c")
f = A("f")
h = A("h")
b = B("b")
e = B("e")
a = A("a")

d.t = i
d.o = c
i.s = h
c.s = d
f.t = b
f.o = b
h.t = b
h.o = b
b.s = d
e.s = a
a.t = c
a.o = e
assert b.s.o.s.o.txt == "c"