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

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

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

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

a = A("a")
j = B("j")
i = C("i")
e = D("e")

a.u = e
a.r = e
a.q = j
j.r = a
i.u = e
e.o = i
e.x = i
assert a.u.o.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.r: D = None
        self.q: B = None
        self.txt = txt

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

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

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

a = A("a")
j = B("j")
i = C("i")
e = D("e")

a.u = e
a.r = e
a.q = j
j.r = a
i.u = e
e.o = i
e.x = i
assert a.u.o.u.x.txt == "i"