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

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

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

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

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

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

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