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

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

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

h = A("h")
k = B("k")
b = C("b")
d = B("d")

h.p = d
h.z = d
h.y = b
k.w = d
k.q = d
k.r = d
b.z = h
b.w = d
d.w = k
d.q = k
d.r = k
assert b.z.y.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.z: B = None
        self.y: C = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
b = C("b")
d = B("d")

h.p = d
h.z = d
h.y = b
k.w = d
k.q = d
k.r = d
b.z = h
b.w = d
d.w = k
d.q = k
d.r = k
assert b.z.y.z.y.txt == "b"