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

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

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

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

m = A("m")
a = B("a")
e = C("e")
h = D("h")
c = D("c")

m.r = a
a.u = c
a.r = m
e.s = m
h.p = a
h.o = a
h.q = m
h.t = m
c.p = a
c.o = a
c.q = m
c.t = m
assert e.s.r.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

m = A("m")
a = B("a")
e = C("e")
h = D("h")
c = D("c")

m.r = a
a.u = c
a.r = m
e.s = m
h.p = a
h.o = a
h.q = m
h.t = m
c.p = a
c.o = a
c.q = m
c.t = m
assert e.s.r.u.q.txt == "m"