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

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

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

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

k = A("k")
m = B("m")
h = C("h")
e = D("e")
f = B("f")

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

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

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

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

k = A("k")
m = B("m")
h = C("h")
e = D("e")
f = B("f")

k.s = e
m.q = k
m.w = f
h.x = e
h.z = e
e.r = h
f.q = k
f.w = m
assert k.s.r.x.txt == "e"