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

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

i = A("i")
m = B("m")
a = B("a")
f = A("f")
e = A("e")
d = A("d")
g = B("g")

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

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

i = A("i")
m = B("m")
a = B("a")
f = A("f")
e = A("e")
d = A("d")
g = B("g")

i.o = m
m.u = a
m.x = g
a.u = m
a.x = g
f.o = a
e.o = a
d.o = g
g.u = m
g.x = a
assert d.o.u.x.u.txt == "m"