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

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

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

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

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

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

a.u = m
m.o = f
m.v = f
i.u = f
e.u = f
f.o = m
f.v = m
assert i.u.v.v.o.txt == "m"