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

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

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

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

d = A("d")
j = B("j")
i = C("i")
b = D("b")
a = C("a")

d.q = j
d.p = b
j.w = a
j.v = b
i.v = a
i.r = a
i.p = b
b.z = j
b.w = i
a.v = i
a.r = i
a.p = b
assert b.z.v.z.w.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: D = None
        self.txt = txt

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

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

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

d = A("d")
j = B("j")
i = C("i")
b = D("b")
a = C("a")

d.q = j
d.p = b
j.w = a
j.v = b
i.v = a
i.r = a
i.p = b
b.z = j
b.w = i
a.v = i
a.r = i
a.p = b
assert b.z.v.z.w.v.txt == "i"