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

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

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

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

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

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

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

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

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

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

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