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

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

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

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

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

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

h.r = d
d.t = h
i.r = d
assert i.r.t.r.txt == "d"