class A:
    def __init__(self, txt: str):
        self.s: D = 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.s: B = None
        self.txt = txt

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

n = A("n")
f = B("f")
h = C("h")
c = D("c")
d = D("d")
b = C("b")

n.s = c
f.z = b
h.s = f
c.z = f
c.q = d
c.p = n
d.z = f
d.q = c
d.p = n
b.s = f
assert d.z.z.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = 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.s: B = None
        self.txt = txt

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

n = A("n")
f = B("f")
h = C("h")
c = D("c")
d = D("d")
b = C("b")

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