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

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

n = A("n")
f = B("f")
c = C("c")
l = D("l")

n.z = f
n.w = l
f.r = c
f.s = n
f.t = n
f.p = l
c.s = f
l.o = f
assert c.s.s.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.w: D = None
        self.txt = txt

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

n = A("n")
f = B("f")
c = C("c")
l = D("l")

n.z = f
n.w = l
f.r = c
f.s = n
f.t = n
f.p = l
c.s = f
l.o = f
assert c.s.s.z.p.txt == "l"