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

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

n = A("n")
m = B("m")
e = A("e")
d = B("d")

n.o = m
m.o = n
m.v = d
e.o = m
d.o = n
d.v = m
assert d.v.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

n = A("n")
m = B("m")
e = A("e")
d = B("d")

n.o = m
m.o = n
m.v = d
e.o = m
d.o = n
d.v = m
assert d.v.o.o.o.txt == "n"