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

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.v: D = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.w: B = None
        self.v: B = None
        self.p: B = None
        self.x: D = None
        self.txt = txt

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

i = A("i")
d = B("d")
k = C("k")
l = D("l")

i.p = l
i.z = k
i.x = d
d.y = k
d.v = l
k.w = d
k.v = d
k.p = d
k.x = l
l.r = d
assert d.y.x.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.z: C = None
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.v: D = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.w: B = None
        self.v: B = None
        self.p: B = None
        self.x: D = None
        self.txt = txt

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

i = A("i")
d = B("d")
k = C("k")
l = D("l")

i.p = l
i.z = k
i.x = d
d.y = k
d.v = l
k.w = d
k.v = d
k.p = d
k.x = l
l.r = d
assert d.y.x.r.v.txt == "l"