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

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.p: A = None
        self.z: D = None
        self.u: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
f = C("f")
d = D("d")
n = C("n")

j.v = i
i.t = d
i.q = j
f.y = d
f.z = d
f.p = j
f.u = i
d.s = i
n.y = d
n.z = d
n.p = j
n.u = i
assert d.s.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.p: A = None
        self.z: D = None
        self.u: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
f = C("f")
d = D("d")
n = C("n")

j.v = i
i.t = d
i.q = j
f.y = d
f.z = d
f.p = j
f.u = i
d.s = i
n.y = d
n.z = d
n.p = j
n.u = i
assert d.s.q.v.txt == "i"