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

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

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

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

l = A("l")
m = B("m")
c = C("c")
k = D("k")
e = C("e")

l.s = c
m.y = l
m.w = l
c.x = e
k.y = m
k.z = m
k.p = l
e.x = c
assert e.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

l = A("l")
m = B("m")
c = C("c")
k = D("k")
e = C("e")

l.s = c
m.y = l
m.w = l
c.x = e
k.y = m
k.z = m
k.p = l
e.x = c
assert e.x.x.x.txt == "c"