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")
j = B("j")
h = A("h")

d.y = j
j.o = d
h.y = j
assert d.y.o.y.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")
j = B("j")
h = A("h")

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