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

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

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

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

a = A("a")
c = B("c")
l = C("l")
j = D("j")

a.s = j
c.u = l
c.q = a
l.y = j
j.x = l
assert l.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

a = A("a")
c = B("c")
l = C("l")
j = D("j")

a.s = j
c.u = l
c.q = a
l.y = j
j.x = l
assert l.y.x.y.txt == "j"