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

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

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

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

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

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

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

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

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

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

h.x = k
h.u = k
h.w = m
k.r = m
k.q = m
k.x = m
k.p = j
j.r = m
j.x = m
m.r = j
m.p = j
m.s = h
assert m.s.w.s.txt == "h"