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

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

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

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

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

d.q = k
i.q = d
i.v = k
n.z = d
k.s = d
k.p = n
assert k.p.z.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

d.q = k
i.q = d
i.v = k
n.z = d
k.s = d
k.p = n
assert k.p.z.q.p.txt == "n"