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

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

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

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

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

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

h.p = f
f.w = b
f.r = b
b.p = f
assert f.r.p.w.txt == "b"