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

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

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

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

b = A("b")
j = B("j")
a = C("a")
n = D("n")
k = A("k")

b.s = k
b.x = j
j.z = a
j.x = a
j.u = b
a.o = k
n.o = b
k.s = b
k.x = j
assert j.z.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.x: B = None
        self.txt = txt

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

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

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

b = A("b")
j = B("j")
a = C("a")
n = D("n")
k = A("k")

b.s = k
b.x = j
j.z = a
j.x = a
j.u = b
a.o = k
n.o = b
k.s = b
k.x = j
assert j.z.o.x.txt == "j"