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

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

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

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

b = A("b")
d = B("d")
j = C("j")
n = D("n")

b.v = n
d.x = b
d.v = n
d.p = n
j.y = d
n.z = j
n.t = b
assert d.x.v.t.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

b = A("b")
d = B("d")
j = C("j")
n = D("n")

b.v = n
d.x = b
d.v = n
d.p = n
j.y = d
n.z = j
n.t = b
assert d.x.v.t.v.txt == "n"