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

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

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

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

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

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

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