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

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

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

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

l = A("l")
j = B("j")
d = C("d")
m = D("m")

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

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

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

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

l = A("l")
j = B("j")
d = C("d")
m = D("m")

l.x = m
j.s = m
j.q = l
j.o = d
d.u = j
d.t = m
m.s = j
m.y = j
m.x = l
m.t = l
assert d.t.x.x.x.txt == "l"