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

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.x: C = None
        self.txt = txt

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

d = A("d")
c = B("c")
n = C("n")
f = B("f")

d.p = f
d.s = f
d.z = n
c.q = f
c.s = f
c.x = n
n.s = c
f.q = c
f.s = c
f.x = n
assert c.s.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.z: C = None
        self.s: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.x: C = None
        self.txt = txt

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

d = A("d")
c = B("c")
n = C("n")
f = B("f")

d.p = f
d.s = f
d.z = n
c.q = f
c.s = f
c.x = n
n.s = c
f.q = c
f.s = c
f.x = n
assert c.s.s.x.s.txt == "c"