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

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

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

l = A("l")
b = B("b")
a = C("a")
d = C("d")
f = A("f")

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

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

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

l = A("l")
b = B("b")
a = C("a")
d = C("d")
f = A("f")

l.p = b
b.z = d
a.r = f
d.r = f
f.p = b
assert d.r.p.z.txt == "d"