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

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

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

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

a = A("a")
m = B("m")
j = C("j")
n = D("n")

a.y = j
m.w = j
j.x = n
n.v = a
n.s = a
n.q = m
n.w = j
assert j.x.s.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

a = A("a")
m = B("m")
j = C("j")
n = D("n")

a.y = j
m.w = j
j.x = n
n.v = a
n.s = a
n.q = m
n.w = j
assert j.x.s.y.x.txt == "n"