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

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

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

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

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

n.u = j
n.w = a
a.y = i
j.x = i
j.r = i
i.s = a
i.q = n
i.x = n
assert j.r.s.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.w: B = None
        self.txt = txt

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

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

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

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

n.u = j
n.w = a
a.y = i
j.x = i
j.r = i
i.s = a
i.q = n
i.x = n
assert j.r.s.y.s.txt == "a"