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

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

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

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

c = A("c")
h = B("h")
m = C("m")
i = D("i")

c.p = i
h.q = m
h.z = c
h.s = i
m.u = h
i.o = m
i.r = h
i.q = h
assert i.o.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

c = A("c")
h = B("h")
m = C("m")
i = D("i")

c.p = i
h.q = m
h.z = c
h.s = i
m.u = h
i.o = m
i.r = h
i.q = h
assert i.o.u.q.txt == "m"