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

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

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

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

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

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

d.t = b
h.y = b
h.r = d
b.y = h
b.r = d
assert h.y.r.t.txt == "b"