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

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

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

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

a = A("a")
i = B("i")
k = C("k")
h = D("h")
m = C("m")

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

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

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

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

a = A("a")
i = B("i")
k = C("k")
h = D("h")
m = C("m")

a.p = h
i.y = m
k.x = h
k.s = i
k.q = a
k.r = a
h.w = i
m.x = h
m.s = i
m.q = a
m.r = a
assert k.r.p.w.y.r.txt == "a"