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

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

d = A("d")
m = B("m")
h = B("h")

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

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

d = A("d")
m = B("m")
h = B("h")

d.y = h
m.o = d
h.o = d
assert m.o.y.o.txt == "d"