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

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

class C:
    def __init__(self, txt: str):
        self.x: C = None
        self.y: C = None
        self.s: A = None
        self.z: 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")
j = C("j")
n = D("n")
m = C("m")

i.v = d
d.r = i
d.w = n
j.x = m
j.y = m
j.s = i
j.z = n
n.r = d
m.x = j
m.y = j
m.s = i
m.z = n
assert i.v.r.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: C = None
        self.y: C = None
        self.s: A = None
        self.z: 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")
j = C("j")
n = D("n")
m = C("m")

i.v = d
d.r = i
d.w = n
j.x = m
j.y = m
j.s = i
j.z = n
n.r = d
m.x = j
m.y = j
m.s = i
m.z = n
assert i.v.r.v.w.txt == "n"