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

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

i = A("i")
d = B("d")
g = A("g")
m = A("m")
l = B("l")
f = B("f")

i.s = f
i.u = d
d.o = l
g.s = f
g.u = f
m.s = d
m.u = l
l.o = d
f.o = d
assert f.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.u: B = None
        self.txt = txt

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

i = A("i")
d = B("d")
g = A("g")
m = A("m")
l = B("l")
f = B("f")

i.s = f
i.u = d
d.o = l
g.s = f
g.u = f
m.s = d
m.u = l
l.o = d
f.o = d
assert f.o.o.o.o.o.txt == "d"