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

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

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

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

n = A("n")
d = B("d")
a = C("a")
g = D("g")
k = D("k")

n.r = d
n.s = g
d.z = k
a.v = k
a.t = n
a.q = d
g.u = d
k.u = d
assert k.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.s: D = None
        self.txt = txt

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

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

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

n = A("n")
d = B("d")
a = C("a")
g = D("g")
k = D("k")

n.r = d
n.s = g
d.z = k
a.v = k
a.t = n
a.q = d
g.u = d
k.u = d
assert k.u.z.u.txt == "d"