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

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

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

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

h = A("h")
j = B("j")
a = C("a")
d = D("d")
k = D("k")

h.s = a
h.r = d
j.t = a
a.z = j
a.y = h
a.v = h
d.z = k
d.x = h
k.z = d
k.x = h
assert a.y.r.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.r: D = None
        self.txt = txt

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

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

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

h = A("h")
j = B("j")
a = C("a")
d = D("d")
k = D("k")

h.s = a
h.r = d
j.t = a
a.z = j
a.y = h
a.v = h
d.z = k
d.x = h
k.z = d
k.x = h
assert a.y.r.z.z.txt == "d"