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

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

f = A("f")
h = B("h")
j = A("j")
l = B("l")

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

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

f = A("f")
h = B("h")
j = A("j")
l = B("l")

f.w = h
f.p = l
h.r = l
j.w = l
j.p = h
l.r = h
assert f.w.r.r.r.txt == "l"