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

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

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

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

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

h.u = k
k.w = a
a.r = j
a.w = j
a.x = k
j.s = h
j.z = h
j.w = a
assert k.w.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

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

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

h.u = k
k.w = a
a.r = j
a.w = j
a.x = k
j.s = h
j.z = h
j.w = a
assert k.w.x.w.txt == "a"