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

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

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

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

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

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

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