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

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

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

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

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

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

h.z = m
l.p = f
l.r = f
m.p = l
m.r = l
f.p = l
f.r = m
assert m.p.r.r.r.txt == "l"