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

k = A("k")
i = B("i")
m = B("m")

k.u = i
i.o = m
i.v = m
m.o = i
m.v = i
assert m.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

k = A("k")
i = B("i")
m = B("m")

k.u = i
i.o = m
i.v = m
m.o = i
m.v = i
assert m.v.v.o.txt == "i"