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

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

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

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

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

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

b.p = a
h.t = a
h.r = a
a.p = b
assert h.r.p.p.txt == "a"