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

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

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

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

k = A("k")
c = B("c")
n = C("n")
h = D("h")
e = D("e")
d = A("d")

k.s = d
k.r = h
c.q = e
n.z = c
n.q = h
h.w = n
e.w = n
d.s = k
d.r = e
assert d.s.s.r.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: D = None
        self.txt = txt

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

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

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

k = A("k")
c = B("c")
n = C("n")
h = D("h")
e = D("e")
d = A("d")

k.s = d
k.r = h
c.q = e
n.z = c
n.q = h
h.w = n
e.w = n
d.s = k
d.r = e
assert d.s.s.r.w.z.txt == "c"