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

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

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

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

d = A("d")
j = B("j")
g = C("g")
e = D("e")
f = C("f")

d.u = e
j.s = d
j.p = d
g.v = f
g.z = e
e.w = j
e.q = f
f.v = g
f.z = e
assert j.p.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

d = A("d")
j = B("j")
g = C("g")
e = D("e")
f = C("f")

d.u = e
j.s = d
j.p = d
g.v = f
g.z = e
e.w = j
e.q = f
f.v = g
f.z = e
assert j.p.u.w.txt == "j"