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

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

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

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

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

i.t = e
i.s = m
m.q = i
e.u = i
c.p = m
c.w = m
c.v = i
c.u = i
assert i.s.q.t.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.s: B = None
        self.txt = txt

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

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

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

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

i.t = e
i.s = m
m.q = i
e.u = i
c.p = m
c.w = m
c.v = i
c.u = i
assert i.s.q.t.u.txt == "i"